n8n
Version:
n8n Workflow Automation Tool
78 lines • 3.86 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PrometheusWorkflowInfoMetricsService = void 0;
const config_1 = require("@n8n/config");
const constants_1 = require("@n8n/constants");
const db_1 = require("@n8n/db");
const di_1 = require("@n8n/di");
const n8n_core_1 = require("n8n-core");
const prom_client_1 = __importDefault(require("prom-client"));
const cache_service_1 = require("../../services/cache/cache.service");
const cached_metric_query_1 = require("./cached-metric-query");
let PrometheusWorkflowInfoMetricsService = class PrometheusWorkflowInfoMetricsService {
constructor(config, workflowRepository, cacheService, instanceSettings) {
this.config = config;
this.workflowRepository = workflowRepository;
this.cacheService = cacheService;
this.instanceSettings = instanceSettings;
}
get enabled() {
return this.config.includeWorkflowInfoMetrics;
}
init() {
this.initGauge({
name: 'workflow_info',
help: 'Map of workflow ID to name. Reported by the leader main only.',
cacheKey: 'metrics:workflow-info:v2',
activeOnly: false,
});
this.initGauge({
name: 'active_workflow_info',
help: 'Map of active workflow ID to name. Reported by the leader main only.',
cacheKey: 'metrics:active-workflow-info:v1',
activeOnly: true,
});
}
initGauge({ name, help, cacheKey, activeOnly }) {
const { instanceSettings } = this;
const cacheTtl = this.config.workflowInfoMetricInterval * constants_1.Time.seconds.toMilliseconds;
const query = new cached_metric_query_1.CachedMetricQuery({
cacheService: this.cacheService,
cacheKey,
ttlMs: cacheTtl,
query: async () => await this.workflowRepository.getWorkflowInfo({ activeOnly }),
});
new prom_client_1.default.Gauge({
name: `${this.config.prefix}${name}`,
help,
labelNames: ['workflow_id', 'workflow_name'],
async collect() {
this.reset();
if (!instanceSettings.isLeader)
return;
const workflows = await query.get();
for (const { id, name: workflowName } of workflows) {
this.labels({ workflow_id: id, workflow_name: workflowName }).set(1);
}
},
});
}
};
exports.PrometheusWorkflowInfoMetricsService = PrometheusWorkflowInfoMetricsService;
exports.PrometheusWorkflowInfoMetricsService = PrometheusWorkflowInfoMetricsService = __decorate([
(0, di_1.Service)(),
__metadata("design:paramtypes", [config_1.PrometheusMetricsConfig, db_1.WorkflowRepository, cache_service_1.CacheService, n8n_core_1.InstanceSettings])
], PrometheusWorkflowInfoMetricsService);
//# sourceMappingURL=workflow-info-metrics.service.js.map