From f7d1263ea669968a4b69d80cede9b77f240de4b6 Mon Sep 17 00:00:00 2001 From: mat Date: Thu, 30 Dec 2021 16:08:47 -0600 Subject: Revert "Revert "add prom-client"" This reverts commit 6ef961dffc700af1929ccaa514df75c476485d38. --- src/index.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src') diff --git a/src/index.ts b/src/index.ts index d0e4fd8..ffa683e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,6 +6,7 @@ import * as discord from './discord.js' import express from 'express' import { getKeyUsage } from './hypixelApi.js' import { basicPlayerCache, basicProfilesCache, playerCache, profileCache, profileNameCache, profilesCache, usernameCache } from './hypixelCached.js' +import { collectDefaultMetrics, register } from 'prom-client' const app = express() @@ -185,6 +186,18 @@ app.post('/accounts/update', async (req, res) => { } }) + +// grafana integration +collectDefaultMetrics() +app.get('/metrics', async (_req, res) => { + try { + res.set('Content-Type', register.contentType) + res.end(await register.metrics()) + } catch (err) { + res.status(500).end(err) + } +}) + process.on('uncaughtException', err => console.error(err)) process.on('unhandledRejection', (err, promise) => console.error(promise, err)) -- cgit