@igor-agafonov/node_metrics_support
v1.0.1
Published
Node metrics support
Readme
node_metrics_support
TypeScript metrics helper built on the official prom-client library.
import {
CounterMetric,
HistogramMetric,
MetricsExporter,
MetricsRegistry,
} from 'node_metrics_support';
MetricsRegistry.configure({ prefix: 'orders' });
CounterMetric.counter('requests', { method: 'GET', route: '/orders' }).inc();
HistogramMetric.histogram('response_seconds', { route: '/orders' }).observe(0.12);
const prometheus = await MetricsExporter.toPrometheus();
const json = await MetricsExporter.toJsonString();All metric classes share the registry configured through MetricsRegistry.
For NestJS, add PrometheusController as a controller. It exposes GET
/api/metrics and GET /api/metrics-json.
CounterMetric, GaugeMetric, SummaryMetric, HistogramMetric, and
Timer provide the metric APIs. Summary quantiles and histogram bucket
configuration are supplied by trailing arguments to summary and histogram.
Timers are curried: Timer.time('work', { operation: 'sync' })(() => doWork()).
Class methods can be annotated: @timer('work').
Scrape-time gauges are curried: GaugeMetric.gaugeOnScrape('queue_depth',
{ queue: 'mail' })(() => currentDepth).
