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