-
-
Notifications
You must be signed in to change notification settings - Fork 289
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
Closed
feat: added ELU metrics #6820
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.", | ||
registers: [register], | ||
buckets: [1, intervalMs / 10, intervalMs / 2, intervalMs], | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
@@ -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(); | ||
}; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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