diff --git a/index.d.ts b/index.d.ts index 432fe0de..ed696e90 100644 --- a/index.d.ts +++ b/index.d.ts @@ -93,6 +93,8 @@ export class AggregatorRegistry extends Registry { * Gets aggregated metrics for all workers. The optional callback and * returned Promise resolve with the same value; either may be used. * @param {Function?} cb (err, metrics) => any + * @param {Object?} opt options for + * @param {Registry?} opt.registry additional registry to merge with * @return {Promise} Promise that resolves with the aggregated * metrics. */ diff --git a/lib/cluster.js b/lib/cluster.js index 89f5c20c..c33ea250 100644 --- a/lib/cluster.js +++ b/lib/cluster.js @@ -17,6 +17,7 @@ const GET_METRICS_REQ = 'prom-client:getMetricsReq'; const GET_METRICS_RES = 'prom-client:getMetricsRes'; let registries = [Registry.globalRegistry]; +let additionRegistry; let requestCtr = 0; // Concurrency control let listenersAdded = false; const requests = new Map(); // Pending requests for workers' local metrics. @@ -31,12 +32,16 @@ class AggregatorRegistry extends Registry { * Gets aggregated metrics for all workers. The optional callback and * returned Promise resolve with the same value; either may be used. * @param {Function?} callback (err, metrics) => any + * @param {Object} opt options for + * @param {Registry} opt.registry additional registry to merge with * @return {Promise} Promise that resolves with the aggregated * metrics. */ - clusterMetrics(callback) { + clusterMetrics(callback, opt) { const requestId = requestCtr++; - + if (opt && opt.registry) { + additionRegistry = opt.registry; + } return new Promise((resolve, reject) => { function done(err, result) { // Don't resolve/reject the promise if a callback is provided @@ -96,6 +101,11 @@ class AggregatorRegistry extends Registry { const aggregatedRegistry = new Registry(); const metricsByName = new Grouper(); + // add addition registry such as master + if (additionRegistry) { + metricsArr.push(additionRegistry.getMetricsAsJSON()); + } + // Gather by name metricsArr.forEach(metrics => { metrics.forEach(metric => { diff --git a/package-lock.json b/package-lock.json index f5446f74..2923e41f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "prom-client", - "version": "11.5.2", + "version": "11.5.3", "lockfileVersion": 1, "requires": true, "dependencies": {