metrics endpoint

This commit is contained in:
sky
2026-02-18 11:07:04 -05:00
parent 493f4dce60
commit fcd4e6ae50

View File

@ -166,6 +166,8 @@ app.post("/api/account/upload", async (req, res, next) => {
app.post("/api/analytics/game", async (req, res) => { app.post("/api/analytics/game", async (req, res) => {
if (req.body && req.body.path.length < 32) { if (req.body && req.body.path.length < 32) {
let game = req.body.path;
if(game == "nso_fix") game = "nso";
const query = top.prepare(` const query = top.prepare(`
INSERT INTO stats (game, plays) INSERT INTO stats (game, plays)
VALUES ($id, 1) VALUES ($id, 1)
@ -185,7 +187,19 @@ app.use("/api/analytics/get", async(req, res) => {
let data = query.all(); let data = query.all();
res.send(data); res.send(data);
return; 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) => { app.post("/api/ai/sendMessage", async (req, res) => {
// take in chat id and message // take in chat id and message