diff --git a/app.ts b/app.ts index dca01d4a..182fc8a5 100644 --- a/app.ts +++ b/app.ts @@ -4,6 +4,7 @@ import { Hono } from "@hono/hono"; import { cors } from "@hono/hono/cors"; import { prettyJSON } from "@hono/hono/pretty-json"; import { secureHeaders } from "@hono/hono/secure-headers"; +import { prometheus } from "@hono/prometheus"; import { getLogger } from "@logtape/logtape"; import { config } from "~/packages/config-manager/index"; import { agentBans } from "./middlewares/agent-bans"; @@ -22,6 +23,18 @@ export const appFactory = async () => { strict: false, }); + const { printMetrics, registerMetrics } = prometheus({ + collectDefaultMetrics: true, + metricOptions: { + requestsTotal: { + customLabels: { + content_type: (c) => + c.res.headers.get("content-type") ?? "unknown", + }, + }, + }, + }); + app.use(ipBans); app.use(agentBans); app.use(bait); @@ -68,6 +81,8 @@ export const appFactory = async () => { credentials: true, }), ); + app.use("*", registerMetrics); + app.get("/metrics", printMetrics); // Disabled as federation now checks for this // app.use(urlCheck); diff --git a/bun.lockb b/bun.lockb index 07970ec5..9e9fcf75 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index aeaef0b8..dd5d7da5 100644 --- a/package.json +++ b/package.json @@ -99,6 +99,7 @@ "@bradenmacdonald/s3-lite-client": "npm:@jsr/bradenmacdonald__s3-lite-client", "@hackmd/markdown-it-task-lists": "^2.1.4", "@hono/hono": "npm:@jsr/hono__hono@4.5.6", + "@hono/prometheus": "^1.0.1", "@hono/zod-validator": "^0.2.2", "@inquirer/confirm": "^3.1.22", "@inquirer/input": "^2.2.9", @@ -136,6 +137,7 @@ "oauth4webapi": "^2.12.0", "ora": "^8.0.1", "pg": "^8.12.0", + "prom-client": "^15.1.3", "qs": "^6.13.0", "sharp": "^0.33.5", "sonic-channel": "^1.3.1",