Zero Configuration Express Api Metrics Monitoring

Jack Yeh
TeamZeroLabs
Published in
2 min readFeb 28, 2020

--

It’s always a good idea to make things simpler.

One of my earliest article on Medium is Node JS Monitoring with Prometheus and Grafana. I covered setting up prometheus, grafana, and a custom setup.js file to collect and aggregate express routes.

The setup.js file exports three methods:

module.exports = { insertMiddleware, setupMetricService, captureAllRoutes };

Which has to be inserted near the main express application like this:

const express = require("express");
const app = express();
const metric = require("./metric/setup");
...
... before all routes definitionmetric.insertMiddleware(app, { normalizePath: false });... after all routes are definedapp.listen(4000, () => console.log("Server is running on port 4000"));metric.captureAllRoutes(app);
metric.setupMetricService();

Since this code wasn’t re-usable yet, I decided to change it into a small npm package, and simplify the signature to a single middleware.

Package api-express-exporter

You can find the package here on github.

The setup is now:

const app = express();

...

// Before all routes

--

--

Jack Yeh
TeamZeroLabs

I monitor your full stack deployment in production, so you can sleep at night. Docker | Kubernetes | AWS | Prometheus | Grafana