A common pattern in koa applications it to gather response times from all received requests, this middleware takes care of collecting common useful metrics automatically.
npm install --save statful-middleware-koa statful-client
yarn add statful-middleware-koa statful-client
const Koa = require("koa");
const app = new Koa();
const Statful = require("statful-client");
const statfulMiddleware = require("statful-middleware-koa");
const statful = new Statful({
/* statful configuration */
});
app.use(statfulMiddleware(statful));
app.listen(3000);
Most of the configuration is done directly in the statful instance. You can read more about the available options directly from the Statful repository.
By default, the follow metrics are collected, with the corresponding tags:
response_time
hostname
method
: GET, POST, PUT ...statusCode
: 200, 400, 404 ...statusCodeCategory
- informational
- success
- redirection
- client_error
- server_error
route
: Either the route handler's name, the route path orunknown_route
. e.g.:/users/:id?
statful-middleware-koa is available under the MIT license. See the LICENSE file for more information.