Prometheus Windows_Exporter Available Labels - Stack Overflow

admin2025-04-17  1

I've setup rules to alert via email in Prometheus AlertManager and I've noticed I can use $hostname with the node_exporter job but not the windows_exporter job.

In the rule, I've configured the following:

annotations:
  summary: "{{ $labels.instance }} instance is down"

If I replace $labels.instance with $labels.hostname, it only works with the node_exporter job but not the windows_exporter job.

Looking at the windows_exporter github page ...

Github Windows Exporter

... the "cs" collector has a hostname label:

  • Name = windows_cs_hostname
  • Labels = hostname, domain, fqdn

How can I use this hostname label in the rule as I'm trying to avoid the port number that comes with $labels.instance.

Thanks.

I've setup rules to alert via email in Prometheus AlertManager and I've noticed I can use $hostname with the node_exporter job but not the windows_exporter job.

In the rule, I've configured the following:

annotations:
  summary: "{{ $labels.instance }} instance is down"

If I replace $labels.instance with $labels.hostname, it only works with the node_exporter job but not the windows_exporter job.

Looking at the windows_exporter github page ...

Github Windows Exporter

... the "cs" collector has a hostname label:

  • Name = windows_cs_hostname
  • Labels = hostname, domain, fqdn

How can I use this hostname label in the rule as I'm trying to avoid the port number that comes with $labels.instance.

Thanks.

Share Improve this question asked Jan 31 at 7:01 twkltwkl 12 bronze badges 5
  • Alert can only use labels that are present in the result data. What is your query, and what does it return? – markalex Commented Jan 31 at 8:29
  • Query is a simple up == 0, unfortunately, the hostname label is only present in node_exporter job and not the windows_exporter job. – twkl Commented Feb 3 at 5:53
  • I don't think presence of hostname label is expected even for node_exporter. See example here – markalex Commented Feb 4 at 8:17
  • How are you specifying your targets in Prometheus config? Using static_configs or some form of service discovery? Also, any chance you have hostname directly specified for each target in config as an additional label? – markalex Commented Feb 4 at 8:19
  • Apologies Markalex, I'm an idiot. I forgot to add the "relabel_configs" to the windows_exporter job. I had only done it for the node_exporter job. Thanks again. – twkl Commented Feb 6 at 0:33
Add a comment  | 

2 Answers 2

Reset to default 0

Funny story ... once i added "relabel_configs" to the Windows Exporter job, it worked great for my alerts.

Not so great for the Grafana Windows Exporter Dashboard (ID:21697). Some of the metrics were showing 2 values:

  • one for {hostname="servername", instance="servername:9182", job="windows_exporter"}
  • and the other for {instance="servername:9182", job="windows_exporter"}

Anyway, that's for another thread. Gonna go get a stiff double shot to drown my sorrows.

I had to add the relabel_configs under both the node_exporter and windows_exporter jobs as follows:

relabel_configs:
  - source_labels: [__address__]
    target_label: instance
  - source_labels: [instance]
    target_label: hostname
    regex: '([^:]+).*'
    replacement: '${1}'

I had missed the above under the Windows_exporter job previously.

Cheers.

转载请注明原文地址:http://anycun.com/QandA/1744877122a88886.html