1.0.3 • Published 2 years ago

@rfcx/prometheus-metrics v1.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

A wrapper around prom-client module to setup custom metrics for Prometheus scrapper.

Histogram class

When creating a Histogram class item you can provide the following arguments:

Gauge class

When creating a Gauge class item you can provide the following arguments: registerName: string, gaugeName: string, help: string, func: Function

  • registerName: string - registry id. must be equal across one app or app department
  • gaugeName: string - gauge id which will be used in further data retrieval (don't use space or special symbols)
  • help: string - description
  • func: Function - a function which returns current data

Usage example

  const { Histogram, Gauge, getRegister } = require('@rfcx/prometheus-metrics')
  const registerName = 'your-app-id'
  new Gauge(registerName, 'uploads_failed', 'Number or failed uploads', () => { return db.getFailedUploads() })
  const histogram = new Histogram(registerName, 'opus', 'Processing time for opus file format', [0.005, 0.05, 0.1, 0.25, 0.5, 1, 1.5, 2, 2.5, 5,])

  // your app processed some data
  histogram.push(0.124)
  histogram.push(0.001)
  histogram.push(1.3341)
  // data for Gauge is returned from callback function

  // an endpoint which returns metrics
  const register = getRegister(registerName)
  router.route('/metrics').get((req, res) => {
    register.metrics()
      .then((metrics) => {
        res.setHeader('Content-Type', register.contentType)
        res.send(metrics)
        register.resetMetrics()
      })
  })

Grafana representation

Histogram

Histogram

Gauge

Gauge

Publishing

Publishing to NPM registry is done automatically via GitHub Actions once new release is published in the GitHub repository. You must have NPM_PUBLISH_TOKEN secret to be defined in your repository or organization. Reference this or this for instructions.

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago