How to use the prom-client.AggregatorRegistry.aggregate function in prom-client

To help you get started, we’ve selected a few prom-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Hydractify / kanna_kobayashi / src / Shard.ts View on Github external
createServer(async (req: IncomingMessage, res: ServerResponse): Promise =>
{
	try
	{
		if (parse(req.url ?? '').pathname === '/metrics')
		{
			const metrics: object[][] = await manager.broadcastEval('this.getMetrics()');
			res.writeHead(200, { 'content-type': register.contentType });
			res.write(AggregatorRegistry.aggregate(metrics).metrics());
		}
		else
		{
			res.writeHead(404, { 'content-type': register.contentType });
			res.write('Route not found');
		}
	}
	catch (e)
	{
		webhook.error('Prometheus', 'Manager', e);

		res.writeHead(500, { 'content-type': register.contentType });
		res.write('Internal Server Error');
	}
	res.end();
}).listen(httpPort, () => webhook.info('Prometheus', 'Manager', 'Listening for requests...'));