npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

opencensus-default-metrics

v0.0.2

Published

Node default metrics collected using opencensus

Downloads

15

Readme

Default metrics for node.js using opencensus

Node version Downloads Count Build Status Known Vulnerabilities Coverage Status License

Collect default nodejs metrics using opencensus framework. This module is inspired and based on the prom-client and node-prometheus-gc-stats package.

Install

Install with npm:

npm i opencensus-default-metrics --save

Install with yarn:

yarn add opencensus-default-metrics

Usage

See example folder for a sample usage. The library does not bundle any web framework. To expose the metrics you have to use the opencensus exporters.

Default metrics

There are some default metrics recommended by Prometheus itself. To collect these, call collectDefaultMetrics

NOTE: Some of the metrics, concerning File Descriptors and Memory, are only available on Linux.

In addition, some Node-specific metrics are included, such as event loop lag, active handles and Node.js version. See what metrics there are in lib/metrics.

collectDefaultMetrics takes 1 options object with 3 entries, a timeout for how often the probe should be fired, an optional prefix for metric names and an opencensus stats object to which metrics should be registered. By default probes are launched every 10 seconds, but this can be modified like this:

const client = require('opencensus-default-metrics');

const collectDefaultMetrics = client.collectDefaultMetrics;

// Probe every 5th second.
collectDefaultMetrics({ timeout: 5000 });

To register metrics to another stats instance, pass it in as stats:

const { globalStats } = require('@opencensus/core');
const client = require('opencensus-default-metrics');

const collectDefaultMetrics = client.collectDefaultMetrics;

collectDefaultMetrics({ stats: globalStats });

To prefix metric names with your own arbitrary string, pass in a prefix:

const client = require('opencensus-default-metrics');

const collectDefaultMetrics = client.collectDefaultMetrics;

// Probe every 5th second.
collectDefaultMetrics({ prefix: 'my_application_' });

You can get the full list of metrics by inspecting client.metricsList.

collectDefaultMetrics returns an identification when invoked, which is a reference to the Timer used to keep the probes going. This can be passed to clearInterval in order to stop all probes.

NOTE: Existing intervals are automatically cleared when calling collectDefaultMetrics.

const client = require('opencensus-default-metrics');

const collectDefaultMetrics = client.collectDefaultMetrics;

const interval = collectDefaultMetrics();

// ... some time later

clearInterval(interval);

NOTE: unref is called on the interval internally, so it will not keep your node process going indefinitely if it's the only thing keeping it from shutting down.

Stop polling default metrics

To stop collecting the default metrics, you have to call the function and pass it to clearInterval.

const client = require('opencensus-default-metrics');

clearInterval(client.collectDefaultMetrics());

// Clear the stats
client.stats.clear();