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