moleculer icon indicating copy to clipboard operation
moleculer copied to clipboard

Incorrect work of metrics in cluster mode

Open intech opened this issue 4 years ago • 6 comments

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.

  1. enable prometheus metrics
  2. moleculer-runner -i 2
  3. 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

intech avatar Sep 07 '20 17:09 intech

Any updates?

h0x91b-wix avatar Dec 14 '20 10:12 h0x91b-wix

Any updates?

h0x91b-wix avatar Feb 16 '22 10:02 h0x91b-wix

Any updates?

I'll try to get it done this weekend

intech avatar Feb 18 '22 13:02 intech

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.

intech avatar Feb 20 '22 00:02 intech

Any updates?

524c avatar Aug 01 '23 21:08 524c

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

h0x91b-wix avatar Aug 02 '23 12:08 h0x91b-wix