Support clustering mode
lala7573 opened this issue · comments
Yeonju Hwang commented
I can add multiple worker but it expose only one worker metrics at a time.
How can I support the cluster mode using this plugin?
Yeonju Hwang commented
I checked out the code, and find out that this library doesn't support AggregatorRegistry
which is for clustering.
Who looking for the way can follow the steps below. It works.
- Use createPrometheusExporterPlugin with each new registry and registry to AggregatorRegistry
- In worker,
const registry = new Registry();
createPrometheusExporterPlugin({ ..., register: registry, defaultMetrics: true, defaultMetricsOption: { register: registry }})
AggregatorRegistry.setRegistry(registry)
- In master, I opened a new metrics server to expose aggregatorRegistry.
const registry = new AggregatorRegistry();
const metricsApp = express()
metricsApp.get('/metrics', async (req, res) => {
try {
const metrics = await aggregatorRegistry.clusterMetrics();
res.set('Content-Type', aggregatorRegistry.contentType);
res.send(metrics);
} catch (ex) {
res.status(500);
res.send(ex.message);
}
res.end()
});
metricsApp.listen({another port})
https://github.com/siimon/prom-client/tree/master#usage-with-nodejss-cluster-module