Skip to content

Commit

Permalink
oop
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik K committed Nov 10, 2023
1 parent 6bdc24f commit 0dcd03d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 26 deletions.
26 changes: 0 additions & 26 deletions src/util/promHandler.js

This file was deleted.

53 changes: 53 additions & 0 deletions src/util/promHandler.ts
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

View workflow job for this annotation

GitHub Actions / build

Parameter 'req' implicitly has an 'any' type.

Check failure on line 22 in src/util/promHandler.ts

View workflow job for this annotation

GitHub Actions / build

Parameter 'res' implicitly has an 'any' type.
res.set("Content-Type", this.registry.contentType());
res.end(await this.registry.metrics());
});
}

increment(counter: string) {
switch (this.counter) {
case "wouldYou":
this.counter = wouldYou;

Check failure on line 31 in src/util/promHandler.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find name 'wouldYou'.
break;
case "neverHaveIEver":
this.counter = neverHaveIEver;

Check failure on line 34 in src/util/promHandler.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find name 'neverHaveIEver'.
break;
case "mostLikely":
this.counter = mostLikely;

Check failure on line 37 in src/util/promHandler.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find name 'mostLikely'.
break;
case "truthOrDare":
this.counter = truthOrDare;

Check failure on line 40 in src/util/promHandler.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find name 'truthOrDare'.
break;
default:
this.counter = wouldYou;

Check failure on line 43 in src/util/promHandler.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find name 'wouldYou'.
}
this.counter.inc();
}

getMetrics() {
return this.registry.metrics();
}
}

module.exports = prometheusClient;

0 comments on commit 0dcd03d

Please sign in to comment.