mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
HTTP Response metrics
This commit is contained in:
parent
d4713cae01
commit
96a8ccb2e6
3 changed files with 18 additions and 9 deletions
15
src/app.ts
15
src/app.ts
|
|
@ -152,18 +152,17 @@ if (Conf.cronEnabled) {
|
||||||
|
|
||||||
app.use('*', rateLimitMiddleware(300, Time.minutes(5)));
|
app.use('*', rateLimitMiddleware(300, Time.minutes(5)));
|
||||||
|
|
||||||
app.use('/api/*', logger(debug));
|
app.use('/api/*', metricsMiddleware, logger(debug));
|
||||||
app.use('/.well-known/*', logger(debug));
|
app.use('/.well-known/*', metricsMiddleware, logger(debug));
|
||||||
app.use('/users/*', logger(debug));
|
app.use('/users/*', metricsMiddleware, logger(debug));
|
||||||
app.use('/nodeinfo/*', logger(debug));
|
app.use('/nodeinfo/*', metricsMiddleware, logger(debug));
|
||||||
app.use('/oauth/*', logger(debug));
|
app.use('/oauth/*', metricsMiddleware, logger(debug));
|
||||||
|
|
||||||
app.get('/api/v1/streaming', streamingController);
|
app.get('/api/v1/streaming', metricsMiddleware, streamingController);
|
||||||
app.get('/relay', relayController);
|
app.get('/relay', metricsMiddleware, relayController);
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
'*',
|
'*',
|
||||||
metricsMiddleware,
|
|
||||||
cspMiddleware(),
|
cspMiddleware(),
|
||||||
cors({ origin: '*', exposeHeaders: ['link'] }),
|
cors({ origin: '*', exposeHeaders: ['link'] }),
|
||||||
signerMiddleware,
|
signerMiddleware,
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,12 @@ export const httpRequestCounter = new Counter({
|
||||||
labelNames: ['method'],
|
labelNames: ['method'],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const httpResponseCounter = new Counter({
|
||||||
|
name: 'http_responses_total',
|
||||||
|
help: 'Total number of HTTP responses',
|
||||||
|
labelNames: ['status', 'path'],
|
||||||
|
});
|
||||||
|
|
||||||
export const streamingConnectionsGauge = new Gauge({
|
export const streamingConnectionsGauge = new Gauge({
|
||||||
name: 'streaming_connections',
|
name: 'streaming_connections',
|
||||||
help: 'Number of active connections to the streaming API',
|
help: 'Number of active connections to the streaming API',
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,14 @@
|
||||||
import { MiddlewareHandler } from '@hono/hono';
|
import { MiddlewareHandler } from '@hono/hono';
|
||||||
|
|
||||||
import { httpRequestCounter } from '@/metrics.ts';
|
import { httpRequestCounter, httpResponseCounter } from '@/metrics.ts';
|
||||||
|
|
||||||
export const metricsMiddleware: MiddlewareHandler = async (c, next) => {
|
export const metricsMiddleware: MiddlewareHandler = async (c, next) => {
|
||||||
const { method } = c.req;
|
const { method } = c.req;
|
||||||
httpRequestCounter.inc({ method });
|
httpRequestCounter.inc({ method });
|
||||||
|
|
||||||
await next();
|
await next();
|
||||||
|
|
||||||
|
const { status } = c.res;
|
||||||
|
const path = c.req.matchedRoutes.find((r) => r.method !== 'ALL')?.path ?? c.req.routePath;
|
||||||
|
httpResponseCounter.inc({ status, path });
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue