mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
feat(core): Hackmation - Add last activity metric (#13237)
This commit is contained in:
parent
b5e2f331cc
commit
272f55b80f
|
@ -38,6 +38,13 @@ describe('PrometheusMetricsService', () => {
|
|||
includeApiStatusCodeLabel: false,
|
||||
includeQueueMetrics: false,
|
||||
},
|
||||
rest: 'rest',
|
||||
form: 'form',
|
||||
formTest: 'form-test',
|
||||
formWaiting: 'form-waiting',
|
||||
webhook: 'webhook',
|
||||
webhookTest: 'webhook-test',
|
||||
webhookWaiting: 'webhook-waiting',
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -145,10 +152,16 @@ describe('PrometheusMetricsService', () => {
|
|||
includeStatusCode: false,
|
||||
});
|
||||
|
||||
expect(promClient.Gauge).toHaveBeenNthCalledWith(2, {
|
||||
name: 'n8n_last_activity',
|
||||
help: 'last instance activity (backend request).',
|
||||
labelNames: ['timestamp'],
|
||||
});
|
||||
|
||||
expect(app.use).toHaveBeenCalledWith(
|
||||
[
|
||||
'/rest/',
|
||||
'/api/',
|
||||
'/rest/',
|
||||
'/webhook/',
|
||||
'/webhook-waiting/',
|
||||
'/webhook-test/',
|
||||
|
|
|
@ -117,7 +117,8 @@ export class PrometheusMetricsService {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set up metrics for server routes with `express-prom-bundle`
|
||||
* Set up metrics for server routes with `express-prom-bundle`. The same
|
||||
* middleware is also utilized for an instance activity metric
|
||||
*/
|
||||
private initRouteMetrics(app: express.Application) {
|
||||
if (!this.includes.metrics.routes) return;
|
||||
|
@ -130,18 +131,31 @@ export class PrometheusMetricsService {
|
|||
includeStatusCode: this.includes.labels.apiStatusCode,
|
||||
});
|
||||
|
||||
const activityGauge = new promClient.Gauge({
|
||||
name: this.prefix + 'last_activity',
|
||||
help: 'last instance activity (backend request).',
|
||||
labelNames: ['timestamp'],
|
||||
});
|
||||
|
||||
activityGauge.set({ timestamp: new Date().toISOString() }, 1);
|
||||
|
||||
app.use(
|
||||
[
|
||||
'/rest/',
|
||||
'/api/',
|
||||
'/webhook/',
|
||||
'/webhook-waiting/',
|
||||
'/webhook-test/',
|
||||
'/form/',
|
||||
'/form-waiting/',
|
||||
'/form-test/',
|
||||
`/${this.globalConfig.endpoints.rest}/`,
|
||||
`/${this.globalConfig.endpoints.webhook}/`,
|
||||
`/${this.globalConfig.endpoints.webhookWaiting}/`,
|
||||
`/${this.globalConfig.endpoints.webhookTest}/`,
|
||||
`/${this.globalConfig.endpoints.form}/`,
|
||||
`/${this.globalConfig.endpoints.formWaiting}/`,
|
||||
`/${this.globalConfig.endpoints.formTest}/`,
|
||||
],
|
||||
metricsMiddleware,
|
||||
(req, res, next) => {
|
||||
activityGauge.reset();
|
||||
activityGauge.set({ timestamp: new Date().toISOString() }, 1);
|
||||
|
||||
metricsMiddleware(req, res, next);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue