mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
feat(core): Hackmation - Add last activity metric (#13237)
This commit is contained in:
@@ -38,6 +38,13 @@ describe('PrometheusMetricsService', () => {
|
|||||||
includeApiStatusCodeLabel: false,
|
includeApiStatusCodeLabel: false,
|
||||||
includeQueueMetrics: 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,
|
includeStatusCode: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
expect(promClient.Gauge).toHaveBeenNthCalledWith(2, {
|
||||||
|
name: 'n8n_last_activity',
|
||||||
|
help: 'last instance activity (backend request).',
|
||||||
|
labelNames: ['timestamp'],
|
||||||
|
});
|
||||||
|
|
||||||
expect(app.use).toHaveBeenCalledWith(
|
expect(app.use).toHaveBeenCalledWith(
|
||||||
[
|
[
|
||||||
'/rest/',
|
|
||||||
'/api/',
|
'/api/',
|
||||||
|
'/rest/',
|
||||||
'/webhook/',
|
'/webhook/',
|
||||||
'/webhook-waiting/',
|
'/webhook-waiting/',
|
||||||
'/webhook-test/',
|
'/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) {
|
private initRouteMetrics(app: express.Application) {
|
||||||
if (!this.includes.metrics.routes) return;
|
if (!this.includes.metrics.routes) return;
|
||||||
@@ -130,18 +131,31 @@ export class PrometheusMetricsService {
|
|||||||
includeStatusCode: this.includes.labels.apiStatusCode,
|
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(
|
app.use(
|
||||||
[
|
[
|
||||||
'/rest/',
|
|
||||||
'/api/',
|
'/api/',
|
||||||
'/webhook/',
|
`/${this.globalConfig.endpoints.rest}/`,
|
||||||
'/webhook-waiting/',
|
`/${this.globalConfig.endpoints.webhook}/`,
|
||||||
'/webhook-test/',
|
`/${this.globalConfig.endpoints.webhookWaiting}/`,
|
||||||
'/form/',
|
`/${this.globalConfig.endpoints.webhookTest}/`,
|
||||||
'/form-waiting/',
|
`/${this.globalConfig.endpoints.form}/`,
|
||||||
'/form-test/',
|
`/${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);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user