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

@ideco/restify-prom-bundle

v3.0.4

Published

Restify prometheus middleware to expose HTTP metrics

Downloads

24

Readme

Restify middleware to export standard http prometheus metrics.

dependencies Status Build Status codecov Known Vulnerabilities

Usage

const promBundle = require('restify-prom-bundle');
const restify = require('restify');

const server = restify.createServer({ /* options */ });

server.pre(promBundle.preMiddleware(server, { /* options */ }));

server.get('/api', (req, res) => {
  // Custom metrics can be added by using the client.
  const counter = new promBundle.client.Gauge(
    'my_custom_counter',
    'My custom counter'
  );

  counter.inc();
  res.end('OK');
});

server.listen(8000);

// The /metrics route is now available with metrics.

Since prom-client is a singleton, it can be accessed from everywhere by just require'ing / import the module, aggregated metrics will be exposed on the route.

API

preMiddleware(server[, options]) => Restify.Handler

Creates the restify pre-middleware to

  • Creates the expose route used by prometheus server to index metrics
  • Setup default metrics you want to measure

Options :

| Name | Type | Default | Description | | --------- | --------- | --------- | --------- | | route | string | '/metrics' | Exposed route (as GET) for metrics. If false no route will be exposed. | | defaults | string[] | All metrics | Name of default metrics (see table below) to add for each routes. | | exclude | string string[] RegExp Function | undefined | URI(s), uri that match regular expression or uri that passed to function returns true that will be excluded from default metrics. | | promDefaultDelay | number | 10000 | How often (ms) should prom-client fire default probes | | maxPathsToCount | number | 100 | How many paths at max should we measure calls on (restify_path_count), use 0 for unlimited (See below. |

Default metrics :

| Name | Metric Name | Type | Description | | --------- | --------- | --------- | --------- | | status | restify_status_codes | Counter | Number of response for each HTTP status code with status_code as label. | | pathDuration | http_request_duration_seconds | Histogram | Duration (seconds) by percentiles taken by each restify-defined path to generate the response with the path, status_code and the method as labels. | | pathCount | restify_path_count | Counter | Number of calls to each path with the path, status_code and the method as labels. |

duration metrics precision will depends on the pre-middleware registering order, the sooner you register (first server.pre() call), the better it will be.

prom-client: client

Singleton instance of prom-client to set custom metrics.

Paths limitation

If a huge number of different non-routed requests (404) are sent to the server, the process will have to keep a restify_path_count label for each one and the process memory will increase undefinitively. In addition, the prometheus (and grafana) service that uses this probes will be flooded. To prevent this situation, number of measured paths are limited to maxPathsToCount.

This does not affect http_request_duration_seconds as it only measures the restify-defined paths, nor restify_status_codes as it's limited to HTTP status codes.

Once maxPathsToMeasure paths are measured, every new paths will be ignored for http_request_duration_seconds and restify_path_count.

Grafana dashboard

A sample grafana dashboard can be found here .