@@ -140,30 +140,29 @@ const t = dbQueryTimer.create({ query: 'SELECT * FROM users' });
140140const duration = t .stop (); // Returns duration in milliseconds
141141```
142142
143- ### ` metrics.periodicGauge (name, interval , fn[, meta]) `
143+ ### ` metrics.pullGauge (name, fn[, meta]) `
144144
145145<!-- YAML
146146added: REPLACEME
147147-->
148148
149- * ` name ` {string} The name of the periodic gauge metric.
150- * ` interval ` {number} The interval in milliseconds between samples.
149+ * ` name ` {string} The name of the pull gauge metric.
151150* ` fn ` {Function} A function that returns the current value.
152151* ` meta ` {Object} Optional metadata to attach to all reports.
153- * Returns: {metrics.PeriodicGauge }
152+ * Returns: {metrics.PullGauge }
154153
155- Creates a gauge that automatically samples a value at regular intervals .
154+ Creates a gauge that samples a value on-demand by calling the provided function .
156155
157156``` mjs
158- import { periodicGauge } from ' node:metrics' ;
157+ import { pullGauge } from ' node:metrics' ;
159158import { cpuUsage } from ' node:process' ;
160159
161- const cpu = periodicGauge (' cpu.usage' , 5000 , () => {
160+ const cpu = pullGauge (' cpu.usage' , () => {
162161 return cpuUsage ().user ;
163162});
164163
165- // Stop sampling when no longer needed
166- cpu .stop ();
164+ // Sample the gauge when needed
165+ cpu .sample ();
167166```
168167
169168## Classes
@@ -184,7 +183,7 @@ added: REPLACEME
184183
185184* {string}
186185
187- The type of the metric (e.g., 'counter', 'gauge', 'periodicGauge ',
186+ The type of the metric (e.g., 'counter', 'gauge', 'pullGauge ',
188187'timer').
189188
190189#### ` metricReport.name `
@@ -301,7 +300,7 @@ added: REPLACEME
301300
302301* {string}
303302
304- The type of the metric (e.g., 'counter', 'gauge', 'periodicGauge ',
303+ The type of the metric (e.g., 'counter', 'gauge', 'pullGauge ',
305304'timer').
306305
307306#### ` metric.name `
@@ -659,17 +658,17 @@ const dbQueryTimer = timer('db.query.duration');
659658const t = dbQueryTimer .create ({ query: ' SELECT * FROM users' });
660659```
661660
662- ### Class: ` PeriodicGauge `
661+ ### Class: ` PullGauge `
663662
664663* Extends: {metrics.Gauge}
665664
666665<!-- YAML
667666added: REPLACEME
668667-->
669668
670- A gauge that automatically samples values at regular intervals .
669+ A gauge that samples values on-demand when the ` sample() ` method is called .
671670
672- #### ` periodicGauge .metric`
671+ #### ` pullGauge .metric`
673672
674673<!-- YAML
675674added: REPLACEME
@@ -679,81 +678,31 @@ added: REPLACEME
679678
680679The underlying metric instance used for reporting.
681680
682- #### ` periodicGauge.interval `
681+ #### ` pullGauge.sample([meta]) `
683682
684683<!-- YAML
685684added: REPLACEME
686685-->
687686
688- * {number}
689-
690- The sampling interval in milliseconds. Setting this property reschedules the timer.
691-
692- #### ` periodicGauge.schedule() `
693-
694- <!-- YAML
695- added: REPLACEME
696- -->
697-
698- Schedules the periodic sampling based on the configured interval. This is called
699- automatically when the gauge is created, but can be called again to reschedule
700- after it has been stopped.
701-
702- ``` mjs
703- import { periodicGauge } from ' node:metrics' ;
704- import { cpuUsage } from ' node:process' ;
705-
706- const cpu = periodicGauge (' cpu.usage' , 5000 , () => {
707- return cpuUsage ().user ;
708- });
709-
710- cpu .stop ();
711-
712- // Reschedule sampling
713- cpu .schedule ();
714- ```
715-
716- #### ` periodicGauge.stop() `
687+ * ` meta ` {Object} Additional metadata for this specific sample.
688+ * Returns: {number} The sampled value.
717689
718- <!-- YAML
719- added: REPLACEME
720- -->
721-
722- Stops the periodic sampling.
690+ Calls the configured function to get the current value and reports it.
723691
724692``` mjs
725- import { periodicGauge } from ' node:metrics' ;
693+ import { pullGauge } from ' node:metrics' ;
726694import { cpuUsage } from ' node:process' ;
727695
728- const cpu = periodicGauge (' cpu.usage' , 5000 , () => {
696+ const cpu = pullGauge (' cpu.usage' , () => {
729697 return cpuUsage ().user ;
730698});
731699
732- // Stop sampling when no longer needed
733- cpu .stop ();
734- ```
735-
736- #### ` periodicGauge[Symbol.dispose]() `
737-
738- <!-- YAML
739- added: REPLACEME
740- -->
741-
742- Allows ` using ` syntax to automatically stop the periodic gauge when done.
743-
744- ``` mjs
745- import { periodicGauge } from ' node:metrics' ;
746- import { cpuUsage } from ' node:process' ;
700+ // Sample the gauge when needed
701+ const value = cpu .sample ();
702+ console .log (` Current CPU usage: ${ value} ` );
747703
748- {
749- using cpu = periodicGauge (' cpu.usage' , 1000 , () => {
750- return cpuUsage ().user ;
751- });
752-
753- // Perform operations that require periodic sampling...
754-
755- // Sampling is automatically stopped here
756- }
704+ // Sample with additional metadata
705+ cpu .sample ({ threshold: ' high' });
757706```
758707
759708
0 commit comments