prom-client
Prometheus client for Node.js exposing counters, gauges, histograms, and a registry that serves metrics text.
Official Documentation ↗v15. Check the official docs for the latest API surface.Installation
npm install prom-clientpnpm add prom-clientMethods
No methods match this filter.
Overview
prom-client is a Prometheus client for Node.js exposing counters, gauges, histograms, and a registry that serves metrics text. This reference lists the most frequently used APIs with accurate signatures and runnable snippets.
Core APIs
Counter— A monotonic counter incremented by one or a given amount, optionally per label set.Histogram— Records a distribution of observations into configurable buckets for latency metrics.register.metrics— Renders the current values of all registered metrics as Prometheus text.
Example
const client = require('prom-client');
const counter = new client.Counter({
name: 'http_requests_total',
help: 'Total HTTP requests',
labelNames: ['route'],
});
counter.inc({ route: '/health' });
Notes
Histogram buckets and label cardinality directly affect cost and accuracy. Keep labels bounded to avoid metric explosion.
Verification
Increment a counter and confirm the metrics endpoint output contains the metric name and the incremented value.
Errors
The following points are quoted verbatim from the official documentation. 来源:https://cdn.jsdelivr.net/gh/siimon/prom-client@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:51:50.386Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.
- If the same metric name exists in both registries, an error will be thrown. (https://cdn.jsdelivr.net/gh/siimon/prom-client@latest/README.md)
FAQ
- What does collectDefaultMetrics provide?
- It registers process-level metrics such as memory, CPU, event loop lag, and garbage collection that many dashboards rely on.
- Why do histogram buckets matter?
- Buckets determine quantile accuracy; choose boundaries around your latency SLOs so key percentiles are estimated well.
- How do I avoid high cardinality?
- Keep label values bounded; never use user ids or URLs with unbounded segments as label values.
Report a problem with this API docOpens a pre-filled issue on GitHub.