Skip to content

Way to provide labels for default metrics? #83

Closed

Description

@goofballLogic

I can't find a way (from reading the code and readme) to add labels to the default metrics. This is important with regard to production deployment so that e.g. process id can be associated without forcing this data to be a grouping.

This is particularly important when needing to override the "instance" label (for pushgateway instances)

Activity

  1. SimenB commented on Mar 21, 2017

    @SimenB
    Contributor

    This is not currently possible, no. I like the idea though, but how do you imagine the API would look like? I might give it a crack

  2. siimon commented on Mar 21, 2017

    @siimon
    Contributor

    I agree, as long as we keep the API simple I don't mind this, but I think that will be the hardest part.

    I guess you could send in a function that returns an object with key values which is the label key and values. But I guess some validation is needed, since it could only be one level deep and not contain any functions etc..

  3. SkeLLLa commented on Mar 27, 2017

    @SkeLLLa
    Contributor

    I also need some kind of such functionality. @siimon probably it could solve the problem if there will be some way to set "default" labels for all metrics. E.g. setting them in some kind of constructor:

    var pc = require('prom-client')({
      defaultLabels: {
        hostname: 'host1.example.com',
        zone: 'us-east'
      }
    })

    and all those labels should be passed to both default metrics constructors and custom. So:

    new Gauge(PROCESS_HEAP , 'Process heap size in bytes.')

    should become:

    new Gauge(PROCESS_HEAP , 'Process heap size in bytes.', Object.keys(defaultLabels))

    and custom metrics:

    var customLabels = ['label1', 'label2'];
    new Gauge('custom_metric' , 'description', Object.keys(defaultLabels).concat(customLabels))

    But to say the truth I don't like such way, because it's a braking change that could affect a lot of modules. I think there should be easier way to solve this.

    At least such approach could be applied to default metrics, after modification of their init function.

  4. bspradling commented on Mar 29, 2017

    @bspradling

    +1 for this request.

  5. SkeLLLa commented on Mar 29, 2017

    @SkeLLLa
    Contributor

    I've found some kind of workaround for me. As I use consul for registering my services I was able to add default labels through counsul tags and parse them with promise consul meta information, but anyway if someone don't have such options there should be some way to do this through this lib.

  6. SkeLLLa commented on May 11, 2017

    @SkeLLLa
    Contributor

    @goofballLogic, @bspradling8 I've made some "progress" according to this issue. The result you could find here: https://gitlab.com/prometheus-nodejs. There are separate plugins that could be initialized separately (see readmes). During initialization you could override metric name, description, add custom labels or disable some metrics.

    I'm currently in progress of porting all existing metrics into such separate plugins. Also there will be some new plugins like universal http/tcp stats plugin. Some metric names have change, so pay attention to it or just use override option to make them look like current. Also I plan to create some meta package or just helper that could start all those plugins with one or two function calls, but for now they should be started separately.

    UPD: Almost all default metrics were ported. Also there's meta-package that installs all of them and provides easy to use API, where you can add labels, override metric names, define regisrty, etc..

  7. assigned and unassigned on Jun 24, 2017
  8. SimenB commented on Jul 3, 2017

    @SimenB
    Contributor

    This is done in #137.

    Will be released when #135 lands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions