Socket
Socket
Sign inDemoInstall

@matteodisabatino/express-prometheus-middleware

Package Overview
Dependencies
157
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @matteodisabatino/express-prometheus-middleware

Exposes Prometheus metrics for express applications


Version published
Maintainers
1
Created

Changelog

Source

3.1.0 (2022-05-29)

Features

  • updated @matteodisabatino/gc_info to support node v18 (9e07afd)

Readme

Source

express-prometheus-middleware

Exposes Prometheus metrics for express applications. Based on @trussle/tricorder.

By default, the module exposes information about Prometheus default metrics, garbage collection metrics and the duration and the throughput of each HTTP route that has been called at least once via endpoint /metrics. However, you can customize this behaviour via options.

Since version 1.0.0 the module supports all existing Node.js versions from 6.0.0. express and prom-client are required as peer dependencies.

Since version 3.0.0 the module has got its own official Grafana dashboard. Please note that to have information about usage of CPU and RAM, node_exporter must be used in conjunction.

The module is write in TypeScript following the Google TypeScript Style Guide. If you find something not compliant with, please provide a pull request.

In general every pull request that will:

  • Let the code be compliant to Google TypeScript Style Guide
  • Improve performances
  • Add features

are well accepted.

Available options

OptionsTypeMeaningDefault value
collectDefaultMetricsboolean | Prometheus.DefaultMetricsCollectorConfigurationWhether or not to collect Prometheus default metrics or configuration for prom-clienttrue
collectGCMetricsbooleanWhether or not to collect garbage collection metricstrue
exclude(req: express.Request): booleanAvoid all matching routes to expose duration and throughput information(req) => false
excludePathsstring[]Avoid all matching paths to expose duration and throughput information[]
urlstringThe path to which expose metrics/metrics

Usage

Require the module, instance an object and use the handler as an express middleware.

Basic

const express = require('express')
const { ExpressPrometheusMiddleware } = require('@matteodisabatino/express-prometheus-middleware')

const app = express()
const epm = new ExpressPrometheusMiddleware()

app.use(epm.handler)

app.listen(process.env.PORT, () => {
  console.log('Server has been started')
})

Example of advanced usage

const express = require('express')
const { ExpressPrometheusMiddleware } = require('@matteodisabatino/express-prometheus-middleware')

const app = express()
const epm = new ExpressPrometheusMiddleware({
  exclude: (req) => req.method === 'POST' && req.path === '/accounts'
  // This setting will prevent to generate the duration and the throughput
  // metrics for route POST /accounts
})

app.use(epm.handler)

app.listen(process.env.PORT, () => {
  console.log('Server has been started')
})

Keywords

FAQs

Last updated on 29 May 2022

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc