generated from mezotv/Discord-Bot-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dominik K
committed
Nov 10, 2023
1 parent
6bdc24f
commit 0dcd03d
Showing
2 changed files
with
53 additions
and
26 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const express = require("express"); | ||
const promClient = require("prom-client"); | ||
|
||
const { client } = require("./wouldYou"); | ||
|
||
class prometheusClient { | ||
private registry; | ||
private counter; | ||
constructor() { | ||
this.registry = new promClient.Registry(); | ||
this.counter = new promClient.Counter({ | ||
name: "example_counter", | ||
help: "A simple example counter metric", | ||
registers: [this.registry], | ||
}); | ||
|
||
const app = express(); | ||
|
||
app.use(express.json()); | ||
|
||
// Expose Prometheus metrics endpoint | ||
app.get("/metrics", async (req, res) => { | ||
Check failure on line 22 in src/util/promHandler.ts GitHub Actions / build
|
||
res.set("Content-Type", this.registry.contentType()); | ||
res.end(await this.registry.metrics()); | ||
}); | ||
} | ||
|
||
increment(counter: string) { | ||
switch (this.counter) { | ||
case "wouldYou": | ||
this.counter = wouldYou; | ||
break; | ||
case "neverHaveIEver": | ||
this.counter = neverHaveIEver; | ||
break; | ||
case "mostLikely": | ||
this.counter = mostLikely; | ||
break; | ||
case "truthOrDare": | ||
this.counter = truthOrDare; | ||
break; | ||
default: | ||
this.counter = wouldYou; | ||
} | ||
this.counter.inc(); | ||
} | ||
|
||
getMetrics() { | ||
return this.registry.metrics(); | ||
} | ||
} | ||
|
||
module.exports = prometheusClient; |