From 34167c4d996b68aa3b249e1ccd0cda933d7163dff2894d47f360fc86b57fedc5 Mon Sep 17 00:00:00 2001 From: localhorst Date: Sat, 18 Jan 2025 19:36:44 +0100 Subject: [PATCH] export metric for gnss locations --- server/src/controller/metricsController.ts | 7 +++++++ server/src/repositories/locationRepository.ts | 5 +++-- server/src/services/locationService.ts | 10 ++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/server/src/controller/metricsController.ts b/server/src/controller/metricsController.ts index 69f12bc..1f62a40 100644 --- a/server/src/controller/metricsController.ts +++ b/server/src/controller/metricsController.ts @@ -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); diff --git a/server/src/repositories/locationRepository.ts b/server/src/repositories/locationRepository.ts index 5f0a563..e5b4cb4 100644 --- a/server/src/repositories/locationRepository.ts +++ b/server/src/repositories/locationRepository.ts @@ -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>) { + return await Location.findAll(options); } public async findById(id: string) { diff --git a/server/src/services/locationService.ts b/server/src/services/locationService.ts index cb8f10b..e04c177 100644 --- a/server/src/services/locationService.ts +++ b/server/src/services/locationService.ts @@ -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); }