@heyhru/server-plugin-metrics
v0.7.2
Published
Fastify metrics plugin: Prometheus registry, HTTP duration histogram, /metrics endpoint
Downloads
299
Readme
@heyhru/server-plugin-metrics
Fastify plugin for Prometheus metrics collection. Exposes a /metrics endpoint and tracks HTTP request duration.
Install
pnpm add @heyhru/server-plugin-metricsUsage
import Fastify from "fastify";
import { metricsPlugin } from "@heyhru/server-plugin-metrics";
const app = Fastify();
await app.register(metricsPlugin);
// GET /metrics returns Prometheus-format metricsAPI
metricsPlugin
Fastify plugin (wrapped with fastify-plugin).
- Decorates each request with
_reqStartMsto measure duration - Records
http_request_duration_secondshistogram (labels:method,route,status_code) - Registers
GET /metricsendpoint (log level: silent)
Exports
| Export | Type | Description |
| ----------------------- | ----------- | ---------------------------------------- |
| metricsPlugin | Plugin | Fastify plugin |
| register | Registry | Prometheus registry (for custom metrics) |
| httpRequestDuration | Histogram | HTTP request duration histogram |
| Histogram | Class | Re-exported from prom-client |
| Gauge | Class | Re-exported from prom-client |
| Counter | Class | Re-exported from prom-client |
| Summary | Class | Re-exported from prom-client |
