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

menoetius

v0.0.3

Published

node middleware to automatically instrument node applications for consumption by prometheus

Downloads

3,111

Readme

Menoetius

CircleCI Coverage Status Dependencies Status

NPM

Middleware to automatically instrument node applications for consumption by a Prometheus server.

Prometheus is an open source monitoring solution that obtains metrics from servers by querying against the /metrics endpoint upon them.

Once instrumented, Menoetius automatically serves response duration metrics, plus nodejs system metrics on the /metrics endpoint ready to be consumed by Prometheus.

Menoetius will instrument websites and webservices that use http, express, hapi and restify.

Instrumentation

Menoetius automatically measures a number of metrics once instrumented. The following metrics are instrumented via the /metrics endpoint:

Duration Metrics

There are two metrics measuring request duration:

  • http_request_duration_milliseconds (summary): a summary metric measuring the duration in milliseconds of all requests. It can be used to calculate average request durations.
  • http_request_buckets_milliseconds (histogram): a histogram metric used to count duration in buckets of sizes 500ms and 2000ms. This can be used to calculate apdex using a response time threshold of 500ms.

In each case, the following labels are used:

  • status: the http status code of the response, e.g. 200, 500
  • method: the http method of the request, e.g. put, post.
  • path: the path of the request. Note that /users/freddie is labelled /users/ so as not to flood prometheus with labels
  • cardinality: the cardinality of the request, e.g. /users/freddie has cardinality 'one', /users/ has cardinality 'many'

System Metrics

These are metrics provided by prom-client that instrument the nodejs heap/rss usage and cpu usage etc.

Installation

> npm install --save menoetius

Menoetius has only one method, instrument, and it has the following signature:

instrument(server, options)

The first argument represents the server of the middleware.

The second argument is optional, and allows some configuration of menoetius

  • url - the url on which to serve metrics. Defaults to /metrics.

See the following examples of use with http, express, hapi and restify.

http

const http = require('http');
const menoetius = require('../../index');

const server = http.createServer((req, res) => {
  if(req.url !== '/metrics') {
    res.statusCode = 200;
    res.end();
  }
});

menoetius.instrument(server);

server.listen(8003, '127.0.0.1', () => {
  console.log('http listening on 8003');
});

Express

const express = require('express');
const menoetius = require('menoetius');

const app = express();
menoetius.instrument(app);

app.get('/', (req, res) => {
  res.send();
});

app.listen(3000, () => {
  console.log('express server listening on port 3000');
});

Hapi

const Hapi = require('hapi');
const menoetius = require('menoetius');

const server = Hapi.Server({
    port: 8002
})

async function init() {
  try {
    await epithemeus.instrument(server);

    server.route({
      method: 'GET',
      path: '/',
      handler: async (request, h) => {
        return h.response()
      }
    })

    await server.start()

    console.log(`Hapi ${server.version} server listening on port 8002`)

  } catch(err) {
    console.log('Error', err);
    process.exit(1);
  }

}

init();

Restify

const restify = require('restify');
const menoetius = require('menoetius');

const server = restify.createServer();

menoetius.instrument(this.server);

server.get('/', (req, res, done) => {
  res.send();
  done();
});

server.listen(3000, () => {
  console.log('restify server listening on port 3000');
});

Try It Out

The docker-compose.yml file in the examples directory will create a prometheus server and an example each of an http, express, hapi and restify server.

Assuming you have installed docker and docker-compose, you can try it out by doing the following:

> cd examples
> docker-compose up

You can then view the prometheus server on http://127.0.0.1:9090

Etymology

Menoetius

Menoetius was a Titan god, son of Titans Iapetus and Clymene, and brother of Atlas, Prometheus and Epimetheus. His name derives from the Ancient Greek words "menos" (might) and "oitos" (doom), meaning "doomed might".

https://www.greekmythology.com/Titans/Menoetius/menoetius.html

Doom also stalks this module as hopefully one day https://github.com/roylines/node-epimetheus/pull/63 will be merged, obviating the need for this module to exist.