From fcd4e6ae509f488b2af44c435263beb6c99c9106 Mon Sep 17 00:00:00 2001 From: sky Date: Wed, 18 Feb 2026 11:07:04 -0500 Subject: [PATCH] metrics endpoint --- index.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index ee77f4e..8f783c0 100755 --- a/index.js +++ b/index.js @@ -166,6 +166,8 @@ app.post("/api/account/upload", async (req, res, next) => { app.post("/api/analytics/game", async (req, res) => { if (req.body && req.body.path.length < 32) { + let game = req.body.path; + if(game == "nso_fix") game = "nso"; const query = top.prepare(` INSERT INTO stats (game, plays) VALUES ($id, 1) @@ -185,7 +187,19 @@ app.use("/api/analytics/get", async(req, res) => { let data = query.all(); res.send(data); return; -}) +}); +app.use("/metrics", async(req, res) => { + const query = top.prepare(`SELECT * FROM stats ORDER BY plays DESC`); + let data = query.all(); + let returnData = "#HELP game_plays_total The total number of plays per game.\n"; + returnData+="#TYPE game_plays_total counter\n" + data.forEach(e => { + returnData+=`game_plays_total{name="${e.game}"} ${e.plays}\n` + }); + res.setHeader("Content-Type", "text/plain; version=0.0.4") + res.send(returnData); + return; +}); app.post("/api/ai/sendMessage", async (req, res) => { // take in chat id and message