Node.js metrics with Prometheus

JavaScript has similar client libraries to Python. In fact, it is even easier to instrument Node.js express applications with the use of express-prom-bundle, which in turn uses prom-client. You can install this library for your use with this command:

npm install express-prom-bundle --save

You can then use it in your code. The following will set up a middleware for express:

const promBundle = require("express-prom-bundle");const metricsMiddleware = promBundle({includeMethod: true});

And then, you simply include the middleware, as you're setting up this application:

app.use(metricsMiddleware)

The example code at https://github.com/kubernetes-for-developers/kfd-nodejs has these updates, and you can check out this ...

Get Kubernetes for Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.