Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added ELU metrics #6820

Closed
wants to merge 4 commits into from
Closed
Changes from 2 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
57 changes: 54 additions & 3 deletions packages/beacon-node/src/metrics/nodeJsMetrics.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,51 @@
import {collectDefaultMetrics, Registry} from "prom-client";
import {EventLoopUtilization, performance} from "node:perf_hooks";
import {collectDefaultMetrics, Histogram, Registry} from "prom-client";
import {gcStats} from "@chainsafe/prometheus-gc-stats";

/**
* Collects event loop utilization metrics compared to the last call
*/
function collectEventLoopUtilization(register: Registry, prefix?: string, intervalMs: number = 5000): () => void {
const key = `${prefix}_` ?? "";

const metricUtilization = new Histogram({
name: `${key}nodejs_eventloop_utilization`,
help: "Histogram of Event Loop utilization between two successive calls.",
registers: [register],
buckets: [0.001, 0.01, 0.1, 0.5, 1],
});

const metricIdle = new Histogram({
name: `${key}nodejs_eventloop_idle`,
help: "Histogram of Event Loop idle time between two successive calls.",
registers: [register],
buckets: [1, intervalMs / 10, intervalMs / 2, intervalMs],
});

const metricActive = new Histogram({
name: `${key}nodejs_eventloop_active`,
help: "Histogram of Event Loop active time between two successive calls.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is in seconds? sould be reflected in the metric name

Suggested change
name: `${key}nodejs_eventloop_active`,
name: `${key}nodejs_eventloop_active_seconds`,

registers: [register],
buckets: [1, intervalMs / 10, intervalMs / 2, intervalMs],
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all metrics need to be in seconds, including buckets


const previousEventLoopUtilizations = new Map<string, EventLoopUtilization>();
const interval = setInterval(() => {
jeluard marked this conversation as resolved.
Show resolved Hide resolved
const previousElu = previousEventLoopUtilizations.get(key);
const currentElu = performance.eventLoopUtilization();
const {utilization, idle, active} = performance.eventLoopUtilization(currentElu, previousElu);
metricUtilization.observe(utilization); /* between 0-1 */
metricIdle.observe(idle); /* in ms, max `intervalMs` */
metricActive.observe(active); /* in ms, max `intervalMs` */
previousEventLoopUtilizations.set(key, currentElu);
}, intervalMs);

return () => {
clearInterval(interval);
previousEventLoopUtilizations.clear();
};
}

export function collectNodeJSMetrics(register: Registry, prefix?: string): () => void {
collectDefaultMetrics({
register,
Expand All @@ -9,11 +54,17 @@ export function collectNodeJSMetrics(register: Registry, prefix?: string): () =>
eventLoopMonitoringPrecision: 10,
});

const terminateEluCollection = collectEventLoopUtilization(register, prefix);

// Collects GC metrics using a native binding module
// - nodejs_gc_runs_total: Counts the number of time GC is invoked
// - nodejs_gc_pause_seconds_total: Time spent in GC in seconds
// - nodejs_gc_reclaimed_bytes_total: The number of bytes GC has freed
// `close` must be called to stop the gc collection process from continuing
const close = gcStats(register, {collectionInterval: 6000, prefix});
return close;
const terminateGCCollection = gcStats(register, {collectionInterval: 6000, prefix});

return () => {
terminateGCCollection();
terminateEluCollection();
};
}
Loading