Keeping specific systemd name labels

202 views
Skip to first unread message

Emre Kiratli

unread,
Nov 20, 2020, 5:20:18 AM11/20/20
to Prometheus Users
https://github.com/prometheus/prometheus/issues/3092

This is my current issue i just want to watch mysql,postgresql labels and drop the rest. Did anyone figure this out?

Emre Kiratli

unread,
Nov 20, 2020, 5:24:15 AM11/20/20
to Prometheus Users
^((?!.*myspecificservice.*).)*$  does not work

prom log :

err="parsing YAML file /etc/config/prometheus.yml: error parsing regexp: invalid or unsupported Perl syntax: `(?!`"  

20 Kasım 2020 Cuma tarihinde saat 13:20:18 UTC+3 itibarıyla Emre Kiratli şunları yazdı:

Matthias Rampke

unread,
Nov 20, 2020, 8:52:35 AM11/20/20
to Emre Kiratli, Prometheus Users
Go regexes unfortunately do not support negative matches. I believe you can get the behavior that you need by having a temporary label, and changing it based on the various conditions:

1. you want to keep all metrics by default (action replace, target __tmp_keep, replacement "yes")
2. you want to drop all unit state metrics (action replace, source labels __name__, match "node_systemd_unit_state", target __tmp_keep, replacement "no")
3. you want to keep all unit state metrics where name matches (action replace, source labels [__name__,name], match "node_systemd_unit_state;(mysql|postrgresql).*", target __tmp_keep, replacement yes)
4. act on the temporary label (action keep, source labels _tmp_keep, match "yes")

/MR

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/34494ea5-a7c3-41a5-8425-3848d4bb0f12n%40googlegroups.com.

b.ca...@pobox.com

unread,
Nov 20, 2020, 9:23:00 AM11/20/20
to Prometheus Users
As the error says, you are using unsupported regex syntax.  Prometheus supports the syntax of the RE2 library: https://github.com/google/re2/wiki/Syntax

For more complex ways of combining drop/keep expressions, you can use __tmp labels.  Here is an example which doesn't solve your particular problem exactly, but gives an example of how it can be used:

      # On docker hosts we get many tmpfs/aufs filesystem; lots of NFS mounts too,
      # plus ext4 bind mounts under /run/docker/runtime-runs/moby/
      # Drop all of these, except keep node_filesystem_readonly for NFS mounts.
      - source_labels: [__name__, fstype]
        regex: 'node_filesystem_readonly;(nfs|nfs4|.*gluster.*)'
        target_label: __tmp_keep
        replacement: Y
      - source_labels: [__tmp_keep, fstype]
        regex: ';(aufs|tmpfs|nfs|nfs4|fuse.lxcfs|.*gluster.*)'
        action: drop
      - source_labels: [__tmp_keep, mountpoint]
        regex: ';(/run/.*)'
        action: drop
      - regex: '__tmp.*'
        action: labeldrop

I wanted to drop all labels with specific fstype and mountpoint values, *except* I wanted to keep the node_filesystem_readonly metrics for certain filesystem types.
Reply all
Reply to author
Forward
0 new messages