use Promise.all
This commit is contained in:
parent
34167c4d99
commit
f969b0a4c0
@ -57,18 +57,31 @@ const ttnGatewayReceptions = new Gauge({
|
|||||||
labelNames: ["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) => {
|
||||||
try {
|
try {
|
||||||
console.log("Metric Endpoint triggered");
|
const [
|
||||||
|
allLocations,
|
||||||
|
gnssLocations,
|
||||||
|
allWifiLocations,
|
||||||
|
wifiLocationsNotResolvable,
|
||||||
|
wifiLocationsRequestLimitExceeded,
|
||||||
|
allTtnGatewayReceptions
|
||||||
|
] = await Promise.all([
|
||||||
|
locationService.getAllLocations(),
|
||||||
|
locationService.getAllGnssLocations(),
|
||||||
|
wifiLocationService.getAllWifiLocations(),
|
||||||
|
wifiLocationService.getAllWifiLocationsByNotResolvable(),
|
||||||
|
wifiLocationService.getAllWifiLocationsByRequestLimitExceeded(),
|
||||||
|
ttnGatewayReceptionService.getAllGatewayReceptions()
|
||||||
|
]);
|
||||||
|
|
||||||
locationsTotal.set((await locationService.getAllLocations()).length);
|
locationsTotal.set(allLocations.length);
|
||||||
gnssLocationsTotal.set((await locationService.getAllGnssLocations()).length);
|
gnssLocationsTotal.set(gnssLocations.length);
|
||||||
wifiLocationTotal.set((await wifiLocationService.getAllWifiLocations()).length);
|
wifiLocationTotal.set(allWifiLocations.length);
|
||||||
wifiLocationNotResolvable.set((await wifiLocationService.getAllWifiLocationsByNotResolvable()).length);
|
wifiLocationNotResolvable.set(wifiLocationsNotResolvable.length);
|
||||||
wifiLocationRequestLimitExceeded.set((await wifiLocationService.getAllWifiLocationsByRequestLimitExceeded()).length);
|
wifiLocationRequestLimitExceeded.set(wifiLocationsRequestLimitExceeded.length);
|
||||||
ttnGatewayReceptions.set((await ttnGatewayReceptionService.getAllGatewayReceptions()).length);
|
ttnGatewayReceptions.set(allTtnGatewayReceptions.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 });
|
||||||
@ -79,7 +92,6 @@ router.get("/", async (req: Request, res: Response) => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Increment the counter for errors
|
// Increment the counter for errors
|
||||||
requestCounter.inc({ method: req.method, route: req.route.path, status: 500 });
|
requestCounter.inc({ method: req.method, route: req.route.path, status: 500 });
|
||||||
|
|
||||||
console.error("Error running metrics endpoint:", error);
|
console.error("Error running metrics endpoint:", error);
|
||||||
res.status(500).json({ error: "Error running metrics endpoint" });
|
res.status(500).json({ error: "Error running metrics endpoint" });
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user