Expose basic Prometheus metrics

This commit is contained in:
Radon Rosborough 2022-01-23 15:54:08 -08:00
parent 69b3bd286f
commit 3aba7c4394
3 changed files with 28 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import path from "path";
import express from "express";
import ws from "express-ws";
import _ from "lodash";
import * as promClient from "prom-client";
import * as api from "./api.js";
import { aliases, langsPromise } from "./langs.js";
@ -20,12 +21,19 @@ const analyticsTag = (process.env.ANALYTICS_TAG || "").replace(
"$1"
);
promClient.collectDefaultMetrics();
const langs = await langsPromise;
const app = express();
app.set("query parser", (qs) => new URLSearchParams(qs));
app.set("view engine", "ejs");
app.get("/metrics", async (_, res) => {
res.contentType("text/plain; version=0.0.4");
res.send(await promClient.register.metrics());
});
app.get("/", (_, res) => {
if (Object.keys(langs).length > 0) {
res.render(path.resolve("frontend/pages/index"), {

View File

@ -31,6 +31,7 @@
"p-queue": "^6.6.2",
"parse-passwd": "^1.0.0",
"prettier": "^2.3.1",
"prom-client": "^14.0.1",
"regenerator-runtime": "^0.13.7",
"semaphore": "^1.1.0",
"strip-ansi": "^6.0.0",

View File

@ -1362,6 +1362,11 @@ bindings@^1.5.0:
dependencies:
file-uri-to-path "1.0.0"
bintrees@1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/bintrees/-/bintrees-1.0.1.tgz#0e655c9b9c2435eaab68bf4027226d2b55a34524"
integrity sha1-DmVcm5wkNeqraL9AJyJtK1WjRSQ=
bluebird@^3.5.5:
version "3.7.2"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f"
@ -3595,6 +3600,13 @@ process@^0.11.10:
resolved "https://registry.yarnpkg.com/process/-/process-0.11.10.tgz#7332300e840161bda3e69a1d1d91a7d4bc16f182"
integrity sha1-czIwDoQBYb2j5podHZGn1LwW8YI=
prom-client@^14.0.1:
version "14.0.1"
resolved "https://registry.yarnpkg.com/prom-client/-/prom-client-14.0.1.tgz#bdd9583e02ec95429677c0e013712d42ef1f86a8"
integrity sha512-HxTArb6fkOntQHoRGvv4qd/BkorjliiuO2uSWC2KC17MUTKYttWdDoXX/vxOhQdkoECEM9BBH0pj2l8G8kev6w==
dependencies:
tdigest "^0.1.1"
promise-inflight@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/promise-inflight/-/promise-inflight-1.0.1.tgz#98472870bf228132fcbdd868129bad12c3c029e3"
@ -4221,6 +4233,13 @@ tapable@^1.0.0, tapable@^1.1.3:
resolved "https://registry.yarnpkg.com/tapable/-/tapable-1.1.3.tgz#a1fccc06b58db61fd7a45da2da44f5f3a3e67ba2"
integrity sha512-4WK/bYZmj8xLr+HUCODHGF1ZFzsYffasLUgEiMBY4fgtltdO6B4WJtlSbPaDTLpYTcGVwM2qLnFTICEcNxs3kA==
tdigest@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/tdigest/-/tdigest-0.1.1.tgz#2e3cb2c39ea449e55d1e6cd91117accca4588021"
integrity sha1-Ljyyw56kSeVdHmzZEReszKRYgCE=
dependencies:
bintrees "1.0.1"
terser-webpack-plugin@^1.4.3:
version "1.4.5"
resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-1.4.5.tgz#a217aefaea330e734ffacb6120ec1fa312d6040b"