summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2026-05-20 13:51:11 +0200
committerRory& <root@rory.gay>2026-05-28 17:27:08 +0200
commit4a9c6cacc5cadccbf88d910d62e222bf3f4ff5ff (patch)
tree8d73eb497c271c04a2ae3c5414078dcd96e1c3ad /src/util
parentCodeOwners: claim /nix dir (diff)
downloadserver-ts-4a9c6cacc5cadccbf88d910d62e222bf3f4ff5ff.tar.xz
*/Server.ts: Add monitoring init hook
Diffstat (limited to 'src/util')
-rw-r--r--src/util/monitoring/Monitoring.ts38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/util/monitoring/Monitoring.ts b/src/util/monitoring/Monitoring.ts
new file mode 100644

index 00000000..3d6d4ed4 --- /dev/null +++ b/src/util/monitoring/Monitoring.ts
@@ -0,0 +1,38 @@ +/* + Spacebar: A FOSS re-implementation and extension of the Discord.com backend. + Copyright (C) 2026 Spacebar and Spacebar Contributors + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. +*/ + +import * as client from "prom-client"; +import { Router } from "express"; + +export class Monitoring { + static isInitialised = false; + public static async init() { + if (Monitoring.isInitialised) return; + console.log("[Monitoring] Initialising prometheus metrics"); + client.collectDefaultMetrics(); + Monitoring.isInitialised = true; + } + + public static attach(router: Router) { + router.get("/metrics", async (req, res) => { + res.setHeader("Content-Type", client.register.contentType); + const metrics = await client.register.metrics(); + res.send(metrics); + }); + } +}