Prometheus Node.js Middleware

raw JSON →
0.0.3 verified Thu Apr 23 auth: no javascript abandoned

Menoetius is a Node.js middleware designed to automatically instrument web applications and expose Prometheus-compatible metrics. It enables developers to easily gather response duration metrics (summary and histogram types) and fundamental Node.js system metrics, all accessible via a configurable `/metrics` endpoint. The library supports integration with popular HTTP frameworks like `http`, `express`, `hapi`, and `restify`. However, the package is currently at a very early version (0.0.3), was likely published many years ago, and appears to be abandoned, with no discernible updates or active development. It relies on `prom-client` for metric collection, which has evolved significantly since Menoetius's last release. Due to its unmaintained status, it may lack compatibility with modern Node.js versions and up-to-date Prometheus client best practices, making it unsuitable for new projects.

error TypeError: menoetius.instrument is not a function
cause The `menoetius` module was either not properly imported, or the package is corrupted/incomplete.
fix
Ensure npm install menoetius ran successfully and const menoetius = require('menoetius'); is correctly placed. Given the package's age, consider if it's installed alongside incompatible Node.js or dependency versions.
error Error: Cannot find module 'menoetius'
cause The `menoetius` package is not installed in your project's `node_modules` directory.
fix
Run npm install --save menoetius to add the package to your project dependencies.
error Error: The 'request' module is not found. Menoetius requires 'request' as a dependency.
cause Menoetius depends on the `request` package, which is now deprecated and might cause issues with newer Node.js versions or package managers.
fix
While request is likely a transitive dependency, the ultimate fix for Menoetius's issues is to migrate to a modern, maintained Prometheus client solution.
breaking The Menoetius package (version 0.0.3) is extremely old and has been abandoned for several years. It is highly unlikely to be compatible with modern Node.js versions (e.g., Node.js 14+), newer Express.js versions, or the latest `prom-client` APIs. Expect significant breaking changes and runtime errors.
fix Avoid using Menoetius for new projects. For existing applications, consider migrating to a actively maintained Prometheus client library like `prom-client` directly or another up-to-date middleware.
gotcha Menoetius uses an outdated approach to normalize request paths for labels (e.g., `/users/freddie` becomes `/users/`). While this prevents high cardinality, it might mask granular performance issues at specific user or resource endpoints. Modern Prometheus clients often allow more configurable path labeling strategies.
fix Be aware of the path aggregation and ensure it meets your monitoring requirements. If granular path metrics are critical, this library is not suitable.
breaking Due to its abandonment, Menoetius will not receive security updates. Running it in production could expose your application to known or unknown vulnerabilities related to its dependencies or its own code.
fix Upgrade to a actively maintained Prometheus client library and middleware (e.g., `prom-client` directly) to ensure ongoing security patches and compliance.
npm install menoetius
yarn add menoetius
pnpm add menoetius

Demonstrates how to integrate Menoetius with an Express.js application to automatically expose request duration and system metrics on a custom `/metrics-data` endpoint.

const express = require('express');
const http = require('http');
const menoetius = require('menoetius');

const app = express();

// Instrument the Express application
menoetius.instrument(app, { url: '/metrics-data' });

app.get('/', (req, res) => {
  // Simulate some work
  const delay = Math.random() * 200; // 0-200ms
  setTimeout(() => {
    res.status(200).send('Hello from Menoetius-instrumented Express!');
  }, delay);
});

app.get('/slow', (req, res) => {
  // Simulate a slower response
  const delay = Math.random() * 1500 + 500; // 500-2000ms
  setTimeout(() => {
    res.status(200).send('This was a bit slower, check metrics!');
  }, delay);
});

app.get('/error', (req, res) => {
  // Simulate an error response
  res.status(500).send('An internal server error occurred!');
});

const PORT = 3000;
app.listen(PORT, () => {
  console.log(`Express server listening on port ${PORT}`);
  console.log(`Metrics available at http://localhost:${PORT}/metrics-data`);
  console.log('Try hitting /, /slow, and /error endpoints.');
});