moleculer
moleculer copied to clipboard
Incorrect work of metrics in cluster mode
Prerequisites
Please answer the following questions for yourself before submitting an issue.
- [X] I am running the latest version
- [X] I checked the documentation and found no answer
- [X] I checked to make sure that this issue has not already been filed
- [X] I'm reporting the issue to the correct repository
Current Behavior
Metrics are returned in turn from each worker in the cluster and include data about one current worker.
Expected Behavior
It is necessary to transfer the registration of metrics to the cluster master and the workers inform the master about their metrics via IPC or AggregatorRegistry
Steps to Reproduce
Please provide detailed steps for reproducing the issue.
- enable prometheus metrics
- moleculer-runner -i 2
- check metrics
Context
Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.
- Moleculer version: v0.14.10
- NodeJS version: LTS
- Operating System: linux
Any updates?
Any updates?
Any updates?
I'll try to get it done this weekend
It actually turned out to be not as easy a task as I thought when I created this issue. I will need to discuss this with the team. The good news is that this only applies to Prometheus at the moment.
Any updates?
I did a workaround at the end, in my cluster master:
app.get('/metrics', async (req, res) => {
try {
const p = [];
for (let i = 0; i < FORKS; i++) {
p.push(got(`http://localhost:${3030 + 1 + i}/metrics`));
}
const metrics = await Promise.all(p);
res.setHeader('Content-Type', 'text/plain; version=0.0.4; charset=utf-8');
res.send(metrics.map(({ body }) => body).join('\n'));
res.end();
} catch (e) {
console.log('failed to get metrics', e);
res.setHeader('Content-Type', 'text/plain; version=0.0.4; charset=utf-8');
res.status(204);
res.end('');
}
});
Maybe it will help you too