🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

@platformatic/fastify-http-metrics

Package Overview
Dependencies
Maintainers
9
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@platformatic/fastify-http-metrics

The `fastify-http-metrics` package provides a simple way to collect prometheus metrics for your Fastify application.

latest
npmnpm
Version
0.3.0
Version published
Maintainers
9
Created
Source

@platformatic/fastify-http-metrics

The fastify-http-metrics package provides a simple way to collect prometheus metrics for your Fastify application.

Installation

npm install @platformatic/fastify-http-metrics

Usage

const { Registry } = require('prom-client')
const fastify = require('fastify')
const httpMetrics = require('@platformatic/fastify-http-metrics')

const app = fastify()

const registry = new Registry()
app.register(httpMetrics, { registry })

app.get('/metrics', async () => {
  const metrics = await registry.metrics()
  return metrics
})

app.get('/', async () => {
  return 'Hello World'
})

app.listen({ port: 0 }, (err, address) => {
  if (err) {
    console.error(err)
    process.exit(1)
  }
  console.log(`Server listening on ${address}`)
})

API

httpMetrics plugin options

  • options <object> Options for configuring the metrics collection.
    • registry <Registry> The prom-client registry to use for collecting metrics.
    • customLabels <array> A list of custom labels names to add to the metrics.
    • getCustomLabels(req, res, server) <function> A function that returns an object of custom labels to add to the metrics. The function receives the request object as a first argument and a response object as a second argument.
    • ignoreMethods <array> A list of HTTP methods to ignore when collecting metrics. Default: ['OPTIONS', 'HEAD', 'CONNECT', 'TRACE'].
    • ignoreRoutes <array> A list of fastify routes to ignore when collecting metrics. Default: [].
    • ignore(req, res, server) <function> A function that returns a boolean indicating whether to ignore the request when collecting metrics. The function receives the request object as a first argument and a response object as a second argument.
    • histogram <object> prom-client histogram options. Use it if you want to customize the histogram.
    • summary <object> prom-client summary options. Use it if you want to customize the summary.
    • zeroFill <boolean> Whether to zero-fill the histogram and summary buckets. Default: false.

License

Apache-2.0

FAQs

Package last updated on 06 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts