Search code examples
prometheusprometheus-node-exporter

Node_exporter node_systemd_unit_state


I want to monitor particular services via node_exporter, without the need to point them in node_exporter service with --collector.systemd.unit-include="(foo|bar)\\.service"

How this should be defined in prometheus config ?

I was trying

- name: Services monitoring
rules:
- alert: Service is down
 expr: node_systemd_unit_state{name="ubrokerd|besclient|boksm|collectd|crond|ldapauth|network|NetworkManager|sshd|tomcat|ubrokerd|nginx|node_exporter\\.service", state="inactive"} == 1
 for: 0m
 labels:
   severity: warning
 annotations:
   summary: service is down on host {{ $labels.instance }}
   description: "Service is down"

but this not seems to work - alert is not firing if any of the services go down


Solution

  • There are two problems with your expr:

    1. You use literal match operator (=) instead of regex match (=~).
    2. You need to put the list inside parentheses, otherwise \\.service applies only to the last item.

    Try this:

     expr: node_systemd_unit_state{name=~"(ubrokerd|besclient|boksm|collectd|crond|ldapauth|network|NetworkManager|sshd|tomcat|ubrokerd|nginx|node_exporter)\\.service", state="inactive"} == 1