export metric for gnss locations

This commit is contained in:
Hendrik Schutter 2025-01-18 19:36:44 +01:00
parent 79580e16b7
commit 34167c4d99
3 changed files with 20 additions and 2 deletions

View File

@ -27,6 +27,12 @@ const locationsTotal = new Gauge({
labelNames: ["database"],
});
const gnssLocationsTotal = new Gauge({
name: `${prefix}gnss_locations_total`,
help: "Total number of location entries with GNSS in database",
labelNames: ["database"],
});
const wifiLocationTotal = new Gauge({
name: `${prefix}wifi_locations_total`,
help: "Total number of wifi location entries in database",
@ -58,6 +64,7 @@ router.get("/", async (req: Request, res: Response) => {
console.log("Metric Endpoint triggered");
locationsTotal.set((await locationService.getAllLocations()).length);
gnssLocationsTotal.set((await locationService.getAllGnssLocations()).length);
wifiLocationTotal.set((await wifiLocationService.getAllWifiLocations()).length);
wifiLocationNotResolvable.set((await wifiLocationService.getAllWifiLocationsByNotResolvable()).length);
wifiLocationRequestLimitExceeded.set((await wifiLocationService.getAllWifiLocationsByRequestLimitExceeded()).length);

View File

@ -1,10 +1,11 @@
import { Attributes, FindOptions } from "sequelize";
import { injectable } from "tsyringe";
import { Location } from "../models/location";
@injectable()
export class LocationRepository {
public async findAll() {
return await Location.findAll();
public async findAll(options?: FindOptions<Attributes<Location>>) {
return await Location.findAll(options);
}
public async findById(id: string) {

View File

@ -1,4 +1,5 @@
import { inject, injectable } from "tsyringe";
import { Op } from 'sequelize';
import { Location } from "../models/location";
import { LocationRepository } from "../repositories/locationRepository";
import { WifiLocationService } from "./wifiLocationService";
@ -52,6 +53,15 @@ export class LocationService {
return this.repository.findAll();
}
public async getAllGnssLocations() {
return this.repository.findAll({
where: {
gnss_latitude: { [Op.ne]: null },
gnss_longitude: { [Op.ne]: null }
}
});
}
public async getLocationById(id: string) {
return this.repository.findById(id);
}