koa-prometheus

0.0.1 • Public • Published

koa-prometheus

NPM version NPM downloads Build Status Coverage Status Dependency Status

Koa middleware to collect some metrics than you can output in prometheus format. Works with koa-router!

How to Install

$ npm install koa-prometheus

Getting Started

First use the koa-prometheus middleware like this:

import Koa from 'koa';
import Router from 'koa-router';
import metricsMiddleware from 'koa-prometheus';
 
// create your router
const router = Router();
/* more router configuration */
 
// create your app
const app = new Koa();
 
// configure middleware
// this ignores requests for static assets
app.use(metricsMiddleware(router, { ignore: [/\.js$/, /\.css$/] });

It will collect two simple metrics for every request: How often it was requested and how long it took to respond. You can now output this in prometheus format on a different endpoint:

import {getMetrics} from 'koa-prometheus';
function metrics(router) {
  return router.get('/metrics', ctx => ctx.body = getMetrics());
}

This endpoint you can now use in combination with other prometheus-compatible tooling.

Dev stuff

How to Test

Run one, or a combination of the following commands to lint and test your code:

$ npm run lint          # Lint the source code with ESLint 
$ npm test              # Run unit tests with Mocha 
$ npm run test:watch    # Run unit tests with Mocha, and watch files for changes 
$ npm run test:cover    # Run unit tests with code coverage by Istanbul 

To launch the documentation site, run:

$ npm install -g easystatic
$ npm start

License

MIT © 2016 Nikolaus Piccolotto

Package Sidebar

Install

npm i koa-prometheus

Weekly Downloads

10

Version

0.0.1

License

MIT

Last publish

Collaborators

  • prayerslayer