add metric TTN Uplinks
This commit is contained in:
		| @ -3,10 +3,12 @@ import { container } from "tsyringe"; | ||||
| import { Counter, Gauge, collectDefaultMetrics, register } from "prom-client"; | ||||
| import { LocationService } from "../services/locationService"; | ||||
| import { WifiLocationService } from "../services/wifiLocationService"; | ||||
| import { TtnGatewayReceptionService } from "../services/ttnGatewayReceptionService"; | ||||
|  | ||||
| const router = express.Router(); | ||||
| const locationService = container.resolve(LocationService); | ||||
| const wifiLocationService = container.resolve(WifiLocationService); | ||||
| const ttnGatewayReceptionService = container.resolve(TtnGatewayReceptionService); | ||||
|  | ||||
| // Collect default system metrics (e.g., CPU, memory usage) | ||||
| const prefix = 'locationhub_'; | ||||
| @ -43,6 +45,12 @@ const wifiLocationRequestLimitExceeded = new Gauge({ | ||||
|   labelNames: ["database"], | ||||
| }); | ||||
|  | ||||
| const ttnGatewayReceptions = new Gauge({ | ||||
|   name: `${prefix}ttn_gateway_receptions`, | ||||
|   help: "Total number of TTN Gateway receptions entries in database", | ||||
|   labelNames: ["database"], | ||||
| }); | ||||
|  | ||||
|  | ||||
| // Define the metrics endpoint | ||||
| router.get("/", async (req: Request, res: Response) => { | ||||
| @ -53,6 +61,7 @@ router.get("/", async (req: Request, res: Response) => { | ||||
|     wifiLocationTotal.set((await wifiLocationService.getAllWifiLocations()).length); | ||||
|     wifiLocationNotResolvable.set((await wifiLocationService.getAllWifiLocationsByNotResolvable()).length); | ||||
|     wifiLocationRequestLimitExceeded.set((await wifiLocationService.getAllWifiLocationsByRequestLimitExceeded()).length); | ||||
|     ttnGatewayReceptions.set((await ttnGatewayReceptionService.getAllGatewayReceptions()).length); | ||||
|  | ||||
|     // Increment the counter with labels | ||||
|     requestCounter.inc({ method: req.method, route: req.route.path, status: 200 }); | ||||
|  | ||||
		Reference in New Issue
	
	Block a user