Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ This release marks our first release under the Prometheus umbrella.

### Added

- Add option to exclude selected default metrics from being collected
- Add `nodejs_eventloop_utilization_summary` and `nodejs_eventloop_utilization_histogram` to the default metrics
- Add debug logging for metrics collection failures.
- Node 26 added to the test matrix
Expand Down
19 changes: 18 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,22 @@ export function exponentialBuckets(
count: number,
): number[];

type AvailableDefaultMetrics =
| 'processCpuTotal'
| 'processStartTime'
| 'osMemoryHeap'
| 'processOpenFileDescriptors'
| 'processMaxFileDescriptors'
| 'eventLoopLag'
| 'eventLoopUtilization'
| 'processResources'
| 'processHandles'
| 'processRequests'
| 'heapSizeAndUsed'
| 'heapSpacesSizeAndUsed'
| 'version'
| 'gc';

export interface DefaultMetricsCollectorConfiguration<
T extends RegistryContentType,
> {
Expand All @@ -878,6 +894,7 @@ export interface DefaultMetricsCollectorConfiguration<
eventLoopUtilizationAgeBuckets?: number;
eventLoopUtilizationMaxAgeSeconds?: number;
labels?: object;
exclude?: AvailableDefaultMetrics[];
}

export const collectDefaultMetrics: {
Expand All @@ -889,7 +906,7 @@ export const collectDefaultMetrics: {
config?: DefaultMetricsCollectorConfiguration<T>,
): void;
/** All available default metrics */
metricsList: string[];
metricsList: AvailableDefaultMetrics[];
};

/**
Expand Down
9 changes: 6 additions & 3 deletions lib/defaultMetrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,13 @@ module.exports = function collectDefaultMetrics(config) {
throw new TypeError('config must be null, undefined, or an object');
}

config = { eventLoopMonitoringPrecision: 10, ...config };
config = { eventLoopMonitoringPrecision: 10, exclude: [], ...config };

for (const metric of Object.values(metrics)) {
metric(config.register, config);
for (const metricGroup of Object.keys(metrics)) {
if (config.exclude.includes(metricGroup)) {
continue;
}
metrics[metricGroup](config.register, config);
}
};

Expand Down
16 changes: 16 additions & 0 deletions test/defaultMetricsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,22 @@ describe.each([
});
});

it('should allow to exclude specific metrics', async () => {
expect(await register.getMetricsAsJSON()).toHaveLength(0);

collectDefaultMetrics();
expect(
await register.getSingleMetric('nodejs_eventloop_lag_seconds'),
).toBeDefined();

register.clear();

collectDefaultMetrics({ exclude: ['eventLoopLag'] });
expect(
await register.getSingleMetric('nodejs_eventloop_lag_seconds'),
).toBeUndefined();
});

describe('disabling', () => {
it('should not throw error', () => {
const fn = function () {
Expand Down
Loading