Skip to content

Allow master to add its own metrics #183

Closed

Description

@miton18

Hi !
I work on clustered Node app.
I have some issues when trying to have worker(s) metrics with cluster ones.

Is master process alllowed to expose his own metrics (registered on default Registry) ?

https://github.com/siimon/prom-client/blob/master/lib/cluster.js#L169

Activity

  1. SimenB commented on Mar 28, 2018

    @SimenB
    Contributor

    I've never used the cluster code, @zbjornson?

  2. miton18 commented on Mar 28, 2018

    @miton18
    Author

    Is there a way to aggregate clusterMetrics() result with default register.metrics

    metricsServer.get('/metrics', (req, res) => {
        aggregatorRegistry.clusterMetrics()
        .then(metrics => {
          res.set('Content-Type', aggregatorRegistry.contentType)
          // How to merge 'metrics' with register.metrics ?
          res.send(metrics))
        })
        .catch(err => {
          error(err)
          return res.status(500).end(err)
        })
      })
  3. zbjornson commented on Mar 29, 2018

    @zbjornson
    Contributor

    @miton18 Since the Prometheus metrics format is plain text, I think that you can just concatenate the string from aggregatorRegistry.clusterMetrics() with the string from masterRegistry.metrics(). From your example (untested):

    metricsServer.get('/metrics', (req, res) => {
        aggregatorRegistry.clusterMetrics()
        .then(metrics => {
          res.set('Content-Type', aggregatorRegistry.contentType)
          metrics += otherRegistry.metrics(); // <-- added
          res.send(metrics))
        })
        .catch(err => {
          error(err)
          return res.status(500).end(err)
        })
      })
  4. miton18 commented on Mar 29, 2018

    @miton18
    Author

    Yes we can... and it's works ;-)

    But I asking if it wasn't interesting to natively add Master metrics with workers ones ?

  5. zbjornson commented on Mar 29, 2018

    @zbjornson
    Contributor

    Ah, probably! Happy to review a PR for that.

  6. brian-brazil commented on Apr 3, 2018

    @brian-brazil

    I think that you can just concatenate the string from aggregatorRegistry.clusterMetrics() with the string from masterRegistry.metrics().

    This will only work if there is no overlap between the metrics, otherwise you could end up with invalid output.

  7. changed the title [-]Allow master to add this own metrics[/-] [+]Allow master to add its own metrics[/+] on Jan 31, 2019
  8. vbrvk commented on Apr 29, 2020

    @vbrvk

    There are any updates? It would be nice to have #280 merged

  9. zbjornson commented on Jan 23, 2021

    @zbjornson
    Contributor

    #280 just need tests. If anyone here can contribute a test, we can get that PR landed!

  10. added 4 commits that reference this issue on Jul 27, 2026
    ce0bc88
    b481839
    0a0f32c
    3c366f7
  11. added 7 commits that reference this issue on Aug 10, 2026
    885cf0d
    71d4d8e
    6a43b14
    1abc9d9
    fe74473
    6336df8
    4725cdc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions