Skip to content

Commit a972f0c

Browse files
committed
Set aggregation method for newer event loop metrics
These are not entirely accurate: they're the "mean of the mean" and "mean of percentiles," but that's as good as we can get. Fixes #418
1 parent c31ccec commit a972f0c

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
1414
- Don't add event listener to `process` if cluster module is not used.
1515
- fix: set labels for default memory metrics on linux
1616
- fix: fix DEP0152 deprecation warning in Node.js v16+
17+
- fix: Set aggregation mode for newer event loop metrics. (Fixes [#418](https://github.com/siimon/prom-client/issues/418))
1718

1819
### Added
1920

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ will only reveal that individual worker's metrics, which is generally
1717
undesirable. To solve this, you can aggregate all of the workers' metrics in the
1818
master process. See `example/cluster.js` for an example.
1919

20-
Default metrics use sensible aggregation methods. Custom metrics are summed
21-
across workers by default. To use a different aggregation method, set the
22-
`aggregator` property in the metric config to one of 'sum', 'first', 'min',
23-
'max', 'average' or 'omit'. (See `lib/metrics/version.js` for an example.)
20+
Default metrics use sensible aggregation methods. (Note, however, that the event
21+
loop lag mean and percentiles are averaged, which is not perfectly accurate.)
22+
Custom metrics are summed across workers by default. To use a different
23+
aggregation method, set the `aggregator` property in the metric config to one of
24+
'sum', 'first', 'min', 'max', 'average' or 'omit'. (See `lib/metrics/version.js`
25+
for an example.)
2426

2527
If you need to expose metrics about an individual worker, you can include a
2628
value that is unique to the worker (such as the worker ID or process ID) in a

lib/metrics/eventLoopLag.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,42 +77,49 @@ module.exports = (registry, config = {}) => {
7777
help: 'The minimum recorded event loop delay.',
7878
registers,
7979
labelNames,
80+
aggregator: 'min',
8081
});
8182
const lagMax = new Gauge({
8283
name: namePrefix + NODEJS_EVENTLOOP_LAG_MAX,
8384
help: 'The maximum recorded event loop delay.',
8485
registers,
8586
labelNames,
87+
aggregator: 'max',
8688
});
8789
const lagMean = new Gauge({
8890
name: namePrefix + NODEJS_EVENTLOOP_LAG_MEAN,
8991
help: 'The mean of the recorded event loop delays.',
9092
registers,
9193
labelNames,
94+
aggregator: 'average',
9295
});
9396
const lagStddev = new Gauge({
9497
name: namePrefix + NODEJS_EVENTLOOP_LAG_STDDEV,
9598
help: 'The standard deviation of the recorded event loop delays.',
9699
registers,
97100
labelNames,
101+
aggregator: 'average',
98102
});
99103
const lagP50 = new Gauge({
100104
name: namePrefix + NODEJS_EVENTLOOP_LAG_P50,
101105
help: 'The 50th percentile of the recorded event loop delays.',
102106
registers,
103107
labelNames,
108+
aggregator: 'average',
104109
});
105110
const lagP90 = new Gauge({
106111
name: namePrefix + NODEJS_EVENTLOOP_LAG_P90,
107112
help: 'The 90th percentile of the recorded event loop delays.',
108113
registers,
109114
labelNames,
115+
aggregator: 'average',
110116
});
111117
const lagP99 = new Gauge({
112118
name: namePrefix + NODEJS_EVENTLOOP_LAG_P99,
113119
help: 'The 99th percentile of the recorded event loop delays.',
114120
registers,
115121
labelNames,
122+
aggregator: 'average',
116123
});
117124
};
118125

0 commit comments

Comments
 (0)