metrics endpoint
This commit is contained in:
16
index.js
16
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
|
||||
|
||||
Reference in New Issue
Block a user