import express from "express"; import client from "prom-client"; const registry = new client.Registry(); const app = express(); var active_users = 0; const users = new client.Gauge({ name: "active_users", help: "active_users", async collect() { this.set(active_users); }, }); registry.registerMetric(users); app.get("/", (req, res) => { res.send("player-metrics"); }); app.post("/api/players", (req, res) => { res.send("ok"); active_users++; }); app.get("/metrics", async (req, res) => { res.setHeader("Content-Type", client.contentType); res.send(await registry.metrics()); res.end(); active_users = 0; // reset the active_users when prometheus gets metrics (aka reset every minute -- prometheus default poll time) }); app.listen(5008, () => { console.log("listening on :" + 5008); });