2

Here's my config:

management.metrics.export.prometheus=true
management.metrics.export.prometheus.pushgateway.enabled=true
management.metrics.export.prometheus.pushgateway.push-rate=1m
management.metrics.export.prometheus.pushgateway.base-url=<IP>:9091
management.metrics.export.prometheus.pushgateway.job=myjob

Looking at the <IP>:9091/metrics endpoint of PushGateway, I see the following tags:

{instance="",job="myjob"}

Ideally, I'd like that "instance" will be the ip address and port of the running service.

It is worth mentioning I used honor_labels: true in the Promethoues conf.

How can I set (automatically if possible) the instance tag?

Thanks

Michael Doubez
  • 5,937
  • 25
  • 39
IsaacLevon
  • 2,260
  • 4
  • 41
  • 83

1 Answers1

4

The following - setting it as key-value in the grouping-key map - should do the trick:

management.metrics.export.prometheus.pushgateway.grouping-key.instance=${hostname:localhost}:${server.port}

You don't necessarily need to set the "job" property as it is derived from spring.application.name and then a fallback. See here.

mweirauch
  • 1,958
  • 11
  • 17
  • 1
    Thanks. I'll mention for future readers that I eventually created `PrometheusPushGatewayManager` bean myself in order to set *instance* tag to `InetAddress.getLocalHost().getHostAddress()`. – IsaacLevon Sep 18 '19 at 11:21
  • "instance" property has to be set to see the value in the metrics – Shankar S Jan 06 '20 at 09:02