jochen-schweizer / express-prom-bundle

express middleware with standard prometheus metrics in one bundle
MIT License
303 stars 67 forks source link

Cluster: Operation timed out. #95

Closed eben0 closed 2 years ago

eben0 commented 3 years ago

I'm trying to run the bundle in a cluster but I get a time out error from prom-client. I'm using the same example from the readme.

const cluster = require('cluster');
const promBundle = require('express-prom-bundle');
const numCPUs = Math.max(2, require('os').cpus().length);
const express = require('express');

if (cluster.isMaster) {
    for (let i = 1; i < numCPUs; i++) {
        cluster.fork();
    }

    const metricsApp = express();
    metricsApp.use('/metrics', promBundle.clusterMetrics());
    metricsApp.listen(9999);

    console.log('cluster metrics listening on 9999');
    console.log('call localhost:9999/metrics for aggregated metrics');
} else {
    const app = express();
    app.use(promBundle({
        autoregister: false, // disable /metrics for single workers
        includeMethod: true
    }));
    app.use((req, res) => res.send(`hello from pid ${process.pid}\n`));
    app.listen(3000);
    console.log(`worker ${process.pid} listening on 3000`);
}

GET http://localhost:9999/metrics

Error: Operation timed out.
    at Timeout._onTimeout (/Users/xxx/git/bim/node_modules/prom-client/lib/cluster.js:59:18)
    at listOnTimeout (internal/timers.js:551:17)
    at processTimers (internal/timers.js:494:7)

Node version: v14.8.0

eben0 commented 3 years ago

Update:

initiating AggregatorRegistry seems to resolve this issue:

new promBundle.promClient.AggregatorRegistry();
disjunction commented 2 years ago

closing, as the example has been updated, thanks to @diegoximenes