Closes the web server used for exposing metrics, if it exists.
This method asynchronously destroys the internal HTTP server instance that serves metrics endpoints. It is safe to call even if the server was never started.
A promise that resolves when the server has been closed.
Cleans up resources used by the Metrics instance.
Specifically, this method clears the internal timer to prevent any further scheduled metric collection or processing. Should be called when the Metrics instance is no longer needed to avoid memory leaks or unintended behavior.
Returns a partial object containing the current metric values.
An object with the current metrics, possibly missing some properties.
Static
startInitializes and starts the Metrics singleton instance with the provided options.
webServerMetricsPort
is specified in the options.Partial configuration options for initializing the Metrics instance.
The singleton instance of Metrics<MetricsValues>
.
Singleton class for collecting and managing application metrics.
The
Metrics
class provides a centralized mechanism to register metric plugins, periodically sample metrics, and expose collected data. It is designed to be instantiated only once via the staticstart
method, enforcing a singleton pattern.Usage
Metrics.start(options)
to initialize and retrieve the singleton instance.register
method.measures()
to retrieve the current metrics as JSON.destroy()
to clean up resources and stop metric collection.Example
Remarks
By default, the class registers memory usage, event loop delay event loop utilization plugins, process uptime and process cpu usage. The sampling interval and resolution can be customized via the
options
parameter.