npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rfcx/prometheus-metrics

v1.0.3

Published

A wrapper around [prom-client](https://github.com/siimon/prom-client) module to setup custom metrics for Prometheus scrapper.

Downloads

7

Readme

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:

  • registerName: string - registry id. must be equal across one app or app department
  • histogramName: string - histogram id which will be used in further data retrieval (don't use space or special symbols)
  • help: string - description
  • buckets: number[] counters which form a cumulative histogram (Optional, Default: [0.005, 0.05, 0.1, 0.25, 0.5, 1, 1.5, 2, 2.5, 5, 7.5, 10, 12.5, 15, 17.5, 20, 25, 30, 35, 40, 45, 50, 75, 100, 150, 200, 250, 375, 500])

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.