Giter VIP home page Giter VIP logo

koa-prometheus's Introduction

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

License

MIT © 2016 Nikolaus Piccolotto

koa-prometheus's People

Contributors

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