David J. Smith
David J. Smith

Reputation: 21

regex to match part of a prometheus label

I've been trying to save the hostname of a FQDN (ie the "xxx" part only from "xxx-xxx-xxx-xxx.sub.domain.com") to another label in prometheus for a couple of hours and I just can't figure it out. None of the the regex I'm using are doing anything:

^([-A-z0-9]+)
^([^.]+)
^[^.]*

Tested the following on https://relabeler.promlabs.com/ with object label address: "xxx-xxx-xxx-xxx.sub.domain.com"

- source_labels: [__address__]
  regex: "from above"
  target_label: instanceID

None of the aforementioned regex change anything.

How can I get "instanceID: xxx-xxx-xxx-xxx" from "address: xxx-xxx-xxx-xxx.sub.domain.com" in prometheus 2.40 relabel_configs?

Upvotes: 1

Views: 839

Answers (1)

David J. Smith
David J. Smith

Reputation: 21

([^\.]+)\..+

Played around a bit and this works just fine

Upvotes: 1

Related Questions