GithubHelp home page GithubHelp logo

ashoksahoo / node-epimetheus Goto Github PK

View Code? Open in Web Editor NEW

This project forked from roylines/node-epimetheus

0.0 2.0 0.0 99 KB

node middleware to automatically instrument node applications for consumption by prometheus

License: MIT License

JavaScript 100.00%

node-epimetheus's Introduction

Epimetheus

CircleCI Coverage Status David

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, Epimetheus automatically serves response duration metrics, plus nodejs system metrics on the /metrics endpoint ready to be consumed by Prometheus.

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

Instrumentation

Epimetheus 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 node-epimetheus

Epimetheus 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 epimetheus

  • 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 epimetheus = require('../../index');

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

epimetheus.instrument(server);

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

Express

const express = require('express');
const epimetheus = require('node-epimetheus');

const app = express();
epimetheus.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 epimetheus = require('node-epimetheus');

const server = new Hapi.Server();

server.connection({
  port: 3000
});

epimetheus.instrument(this.server);

server.route({
  method: 'GET',
  path: '/',
  handler: (req, resp) => {
    resp();
  }
});

server.start(() => {
  console.log('hapi server listening on port 3000');
});

Restify

const restify = require('restify');
const epimetheus = require('node-epimetheus');

const server = restify.createServer();

epimetheus.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

Epimetheus

Epimetheus was one of the Titans and the brother of Prometheus His name is derived from the Greek word meaning 'afterthought', which is the antonym of his brother's name, Prometheus, meaning 'forethought'.

node-epimetheus's People

Contributors

analytik avatar andyroyle avatar ashoksahoo avatar daviddias avatar matteo-hertel avatar roylines avatar spathon avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.