TopGit
GitHub Repo Review

Prometheus client_js: Node.js Metrics Client

prometheus/client_js
PTopGit review image for prometheus/client_js
Review by Topgit.dev for prometheus/client_js, with GitHub repository stats and README context.
Quick verdict

Prometheus client for Node.js is the official library for instrumenting a Node.js process with Counter, Gauge, Histogram, and Summary metrics in Prometheus's exposition format. It stays out of your way — no bundled server, no framework glue, just a registry you call from your own route handler. Reach for it when building metrics a Prometheus server will scrape; skip it if you want an all-in-one APM product that renders dashboards for you too.

Stars
★ 3.5k
Forks
⑂ 413
Language
JavaScript
License
Apache-2.0
Topic
Developer Tools
Updated
Aug 2026
Homepage
GitHub

Understanding the Prometheus Node.js Client

Prometheus client for Node.js is prometheus/client_js, a JavaScript library in the Prometheus GitHub org that implements four metric types — Counter, Gauge, Histogram, and Summary — plus a registry that formats them into scrape-ready text. It doesn't run an HTTP server itself; you decide how `/metrics` gets served. It also understands Node.js's `cluster` module and can emit OpenMetrics.

Core Features for Node.js Application Monitoring

  • Four Prometheus metric types — Counter (`inc()`), Gauge (`set()`/`inc()`/`dec()`/`setToCurrentTime()`), Histogram (`observe()` with configurable buckets), and Summary (`observe()` with configurable percentiles and an optional sliding time window via `maxAgeSeconds`/`ageBuckets`).
  • `collectDefaultMetrics()` pulls in the metrics Prometheus itself recommends plus Node.js-specific ones — event loop lag, active handles, garbage collection, Node.js version — with config knobs like `prefix`, `gcDurationBuckets`, and `eventLoopMonitoringPrecision`.
  • Cluster-mode aggregation through `ClusterRegistry` and `AggregatorRegistry`, so `register.clusterMetrics()` merges every worker's numbers instead of a scrape only ever reaching one process.
  • Label support with three equivalent syntaxes for setting labeled values, label-aware timers, and a `zero()` method to pre-register histogram label combinations before they've been observed.
  • Per-registry default labels via `register.setDefaultLabels()`, applied automatically to every metric that registry emits.
  • Switchable exposition format — classic Prometheus text (0.0.4) or OpenMetrics (1.0.0) — set per registry with `register.setContentType()`.
  • Exemplars on Counter and Histogram metrics, with default metrics auto-populating `traceId`/`spanId` exemplar labels when OpenTelemetry is present.
  • A `Pushgateway` client (`pushAdd`, `push`, `delete`) for jobs that can't sit around waiting to be scraped, plus `linearBuckets()`/`exponentialBuckets()` helpers for histogram configuration.
How this repository's GitHub stars have grown over time. Source: star-history.com.View the star history

Getting Started with Prometheus client_js

The README doesn't spell out an npm install command in its Usage or API sections — every code sample imports the library the same way, `require('@prometheus-io/client')`, which tells you the package identifier but not the exact install invocation. What it does point to for a working setup is the `example/` folder, referenced specifically for cluster and server usage rather than described inline.

Instrumenting Your Node.js Application with Metrics

The basic loop is: create a metric with a mandatory `name` and `help`, call `.inc()`/`.set()`/`.observe()` on it as your code runs, then answer Prometheus's scrape request with `await registry.metrics()` from whatever HTTP handler you're already running — the library doesn't bundle a web framework, so that route is yours to wire up. For values you can only read at scrape time, like current memory usage rather than something accumulated continuously, pass a `collect()` function instead of updating the metric on a timer; the README is specific that `collect()` — sync or async — fires when the registry gathers values, and a `setInterval` callback is the wrong place for those writes. Labels come from a `labelNames` array on the metric config, then get filled in through `.labels(...).set(...)` or by passing a labels object as the first argument to a call like `.inc()`. Running under Node.js's `cluster` module changes the picture: a worker's local registry only reflects that worker's own numbers, so you instantiate `ClusterRegistry` before branching on `cluster.isPrimary`. Skipping that setup in a worker leaves it unable to answer when the primary asks it to aggregate, so `clusterMetrics()` just stalls until it times out. Custom metrics sum across workers by default; set `aggregator` in the metric config to `'first'`, `'min'`, `'max'`, `'average'`, or `'omit'` when summing isn't the right combination for that particular metric.

Strengths

  • All four Prometheus metric types with the configuration knobs the spec actually calls for — sliding-window summaries, custom histogram buckets, custom percentiles — not just a bare wrapper around a counter.
  • Cluster-aware out of the box: `ClusterRegistry`/`AggregatorRegistry` and `register.clusterMetrics()` solve worker-only-sees-itself aggregation without you building custom IPC plumbing.
  • Framework-agnostic. It works with any HTTP layer since exposing metrics is just returning `register.metrics()` from whatever route you pick.
  • Dual exposition-format support — Prometheus text and OpenMetrics — switchable per registry, plus exemplar support tied into OpenTelemetry trace and span IDs on the default metrics.
  • Permissive Apache-2.0 license, maintained under the official prometheus GitHub organization rather than a lone maintainer's account.
  • A Pushgateway client is included rather than left as a separate dependency, with a `requireJobName: false` option for gateways like Gravel Gateway that don't group by job name.

Considerations and Known Limitations

  • No web framework integration is bundled — you have to wire the `/metrics` route into your own HTTP server yourself; the README is explicit that this is left out on purpose.
  • The default file-descriptor and memory metrics are Linux-only per the README's own note, so those particular numbers won't show up when you run the app locally on macOS or Windows.
  • One accuracy caveat called out in the README: cluster aggregation averages the event loop's lag readings — both the mean and the percentile figures — across workers, which is less precise than the sum used for other metrics.
  • Garbage-collection byte-reclaim statistics aren't built in; the README points to a separate module (SimenB/node-prometheus-gc-s) specifically to keep this library free of native dependencies.
  • No npm install command appears in the README sections available here — you have to infer the package identifier from the `require('@prometheus-io/client')` calls in the examples.
  • Combining two registries of different exposition types — Prometheus format with OpenMetrics — has behavior the README labels undefined, so mixing them on one merged endpoint is a risk you take on yourself.

Alternatives for Node.js Metrics Collection

prom-client — a separate, widely used community-maintained Prometheus client for Node.js with a comparable Counter/Gauge/Histogram/Summary API.OpenTelemetry JS SDK — a vendor-neutral instrumentation and metrics API that can export to Prometheus or other backends, not tied to one exposition format.node-statsd — a client for push-based StatsD/UDP metrics sent to a separate daemon, a different delivery model than Prometheus's pull-based scrape.Elastic APM Node.js agent — an APM agent that bundles metrics with distributed tracing and error capture for teams already running the Elastic Stack.

Frequently Asked Questions

What license does Prometheus client_js use?

Prometheus client for Node.js is released under the Apache-2.0 license, as listed on its GitHub repository.

Does Prometheus client_js support Node.js's cluster module?

Prometheus client for Node.js ships a ClusterRegistry that aggregates metrics from every worker into the primary process, since a worker's own registry only reflects its local numbers by default.

Can Prometheus client_js push metrics to a Pushgateway?

Prometheus client for Node.js includes a Pushgateway client with pushAdd, push, and delete methods, plus a requireJobName option for gateways like Gravel Gateway that skip job-name grouping.

What types of metrics does Prometheus client_js support?

Prometheus client for Node.js supports four metric types: Counter, Gauge, Histogram, and Summary.

Does Prometheus client_js support the OpenMetrics format?

Prometheus client for Node.js can emit the OpenMetrics 1.0.0 exposition format per registry, alongside the classic Prometheus 0.0.4 text format it defaults to.

Are there any OS-specific metrics in Prometheus client_js?

Prometheus client for Node.js does have OS-specific metrics: its default file-descriptor and memory readings are only available on Linux, per the README.

The problem it solves

A Node.js process that's slow or failing under load won't tell you why unless something inside it is counting requests, timing them, and tracking memory and event-loop health in a format your monitoring stack can actually scrape. Hand-rolling that layer — picking histogram bucket boundaries, formatting Prometheus's exposition text by hand, keeping Counters from ever going backward — is easy to get subtly wrong. prometheus/client_js exists to standardize that instrumentation layer instead of every team inventing its own metric-naming and formatting conventions.

Best use cases

  • Instrumenting a Node.js HTTP API with request-count Counters and request-duration Histograms that a Prometheus server scrapes on an interval.
  • Aggregating metrics across a Node.js `cluster` deployment where each worker would otherwise only expose its own local numbers.
  • Correlating metrics with distributed traces by attaching exemplars to Counters and Histograms once OpenTelemetry is populating trace and span IDs.
  • Pushing metrics from short-lived batch or cron jobs to a Pushgateway instead of standing up a long-lived process for Prometheus to scrape.
  • Moving a registry from the classic Prometheus text format to OpenMetrics without rewriting the metric-type code that produces the values.

Who should try it — and who should skip

Try Prometheus client for Node.js if you're already running Prometheus, or anything OpenMetrics-compatible, and want real Counter/Gauge/Histogram/Summary types with working cluster-mode aggregation instead of formatting exposition text by hand. Skip it if you don't want to own the `/metrics` HTTP route and a scrape target yourself — an all-in-one APM agent that ships its own collector and dashboard gets you visibility with less setup, at the cost of tying your data to that vendor.

Related repositories

Source & attribution

Facts and code examples sourced from the prometheus/client_js GitHub repository and its README.

GitHub data · last synced Aug 12, 2026Reviewed by Henry
Back to TopGit

Curious whether client_js is right for you?

Let ChatGPT, Claude, or Perplexity look into it — click below and see what AI actually says about client_js.

GitHub