Koa middleware to collect some metrics than you can output in prometheus format. Works with koa-router!
$ npm install koa-prometheus
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.
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
MIT © 2016 Nikolaus Piccolotto