44
55> Stability: 1 - Experimental
66
7- <!-- source_link=lib/metrics.js -->
7+ <!-- source_link=lib/internal/perf/ metrics.js -->
88
9- The ` node: metrics` module provides an API for application instrumentation and
9+ The metrics API provides an API for application instrumentation and
1010performance monitoring. It offers various metric types and built-in exporters
1111for popular monitoring systems.
1212
13- The module can be accessed using:
13+ The metrics API can be accessed using:
1414
1515``` mjs
16- import * as metrics from ' node:metrics ' ;
16+ import { metrics } from ' node:perf_hooks ' ;
1717```
1818
1919``` cjs
20- const metrics = require (' node:metrics ' );
20+ const { metrics } = require (' node:perf_hooks ' );
2121```
2222
2323## Overview
@@ -30,7 +30,8 @@ flexible consumption patterns.
3030### Example
3131
3232``` mjs
33- import { counter } from ' node:metrics' ;
33+ import { metrics } from ' node:perf_hooks' ;
34+ const { counter } = metrics;
3435
3536// Create counter metrics
3637const apiCalls = counter (' api.calls' , { service: ' web' });
@@ -49,7 +50,8 @@ function handleRequest(req, res) {
4950```
5051
5152``` cjs
52- const { counter } = require (' node:metrics' );
53+ const { metrics } = require (' node:perf_hooks' );
54+ const { counter } = metrics;
5355
5456// Create counter metrics
5557const apiCalls = counter (' api.calls' , { service: ' web' });
@@ -82,7 +84,8 @@ added: REPLACEME
8284Creates a counter metric that tracks cumulative values.
8385
8486``` mjs
85- import { counter } from ' node:metrics' ;
87+ import { metrics } from ' node:perf_hooks' ;
88+ const { counter } = metrics;
8689
8790const errorCount = counter (' errors.total' , { component: ' database' });
8891
@@ -105,7 +108,8 @@ added: REPLACEME
105108Creates a gauge metric that represents a single value at a point in time.
106109
107110``` mjs
108- import { gauge } from ' node:metrics' ;
111+ import { metrics } from ' node:perf_hooks' ;
112+ const { gauge } = metrics;
109113import { memoryUsage } from ' node:process' ;
110114
111115const memory = gauge (' memory.usage.bytes' );
@@ -128,7 +132,8 @@ added: REPLACEME
128132Creates a gauge that samples a value on-demand by calling the provided function.
129133
130134``` mjs
131- import { pullGauge } from ' node:metrics' ;
135+ import { metrics } from ' node:perf_hooks' ;
136+ const { pullGauge } = metrics;
132137import { cpuUsage } from ' node:process' ;
133138
134139const cpu = pullGauge (' cpu.usage' , () => {
@@ -292,7 +297,8 @@ specific methods provided by each metric type (e.g., `increment`, `reset`,
292297metadata.
293298
294299``` mjs
295- import { gauge } from ' node:metrics' ;
300+ import { metrics } from ' node:perf_hooks' ;
301+ const { gauge } = metrics;
296302
297303const memoryUsage = gauge (' memory.usage' , { service: ' web' });
298304
@@ -332,7 +338,8 @@ added: REPLACEME
332338Increments the counter by the specified amount.
333339
334340``` mjs
335- import { counter } from ' node:metrics' ;
341+ import { metrics } from ' node:perf_hooks' ;
342+ const { counter } = metrics;
336343
337344const apiCalls = counter (' api.calls' , { service: ' web' });
338345
@@ -354,7 +361,8 @@ added: REPLACEME
354361Decrements the counter by the specified amount.
355362
356363``` mjs
357- import { counter } from ' node:metrics' ;
364+ import { metrics } from ' node:perf_hooks' ;
365+ const { counter } = metrics;
358366
359367const errorCount = counter (' errors.total' , { component: ' database' });
360368
@@ -376,7 +384,8 @@ added: REPLACEME
376384Creates a timer that will increment this counter with its duration when stopped.
377385
378386``` mjs
379- import { counter } from ' node:metrics' ;
387+ import { metrics } from ' node:perf_hooks' ;
388+ const { counter } = metrics;
380389
381390const requestDuration = counter (' request.duration.ms' );
382391
@@ -417,7 +426,8 @@ added: REPLACEME
417426Sets the gauge to a specific value and reports it.
418427
419428``` mjs
420- import { gauge } from ' node:metrics' ;
429+ import { metrics } from ' node:perf_hooks' ;
430+ const { gauge } = metrics;
421431import { memoryUsage } from ' node:process' ;
422432
423433const memory = gauge (' memory.usage.bytes' );
@@ -439,7 +449,8 @@ added: REPLACEME
439449Creates a timer that will set this gauge to its duration when stopped.
440450
441451``` mjs
442- import { gauge } from ' node:metrics' ;
452+ import { metrics } from ' node:perf_hooks' ;
453+ const { gauge } = metrics;
443454
444455const responseTime = gauge (' response.time.ms' );
445456
@@ -497,7 +508,8 @@ added: REPLACEME
497508Stops the timer and reports the duration. Can only be called once.
498509
499510``` mjs
500- import { counter } from ' node:metrics' ;
511+ import { metrics } from ' node:perf_hooks' ;
512+ const { counter } = metrics;
501513
502514const dbQueryDuration = counter (' db.query.duration' );
503515
@@ -518,7 +530,8 @@ added: REPLACEME
518530Allows ` using ` syntax to automatically stop the timer when done.
519531
520532``` mjs
521- import { counter } from ' node:metrics' ;
533+ import { metrics } from ' node:perf_hooks' ;
534+ const { counter } = metrics;
522535
523536const dbQueryDuration = counter (' db.query.duration' );
524537
@@ -553,7 +566,8 @@ added: REPLACEME
553566Calls the configured function to get the current value and reports it.
554567
555568``` mjs
556- import { pullGauge } from ' node:metrics' ;
569+ import { metrics } from ' node:perf_hooks' ;
570+ const { pullGauge } = metrics;
557571import { cpuUsage } from ' node:process' ;
558572
559573const cpu = pullGauge (' cpu.usage' , () => {
0 commit comments