fstab / grok_exporter

Export Prometheus metrics from arbitrary unstructured log data.
Apache License 2.0
890 stars 152 forks source link

regex pattern to capture repeating groups/labels #153

Open harishmk opened 3 years ago

harishmk commented 3 years ago
msg rates = {client1=10, client2=20, client3=15, client4=23}

want to capture the above log line with client name as a label. number of clients is not fixed, i was trying this to extract the metric as dynamic list of labels.

msg rates = \{(%{NUMBER:client}=%{NUMBER:nmsgs}, )*%{NUMBER:client}=%{NUMBER:nmsgs}\}

this seem to capture only the last two items. is there a way to get this working? does the exporter use findAll?

fstab commented 3 years ago

Do you want to create a new label name for each client, like client1="10", client2="20", client3="15", client4="23"? This is not possible. You have to define the labels names when you create the metric. Only the label values are dynamic.

harishmk commented 3 years ago

with the regexp above i was able to create the labels dynamically, but it reports only the last two items. for e.g: with {...client3=15, client4=23} it created client3=15, client4=23 and when the log changed to {...client6=8, client7=27} it created client6=8, client7=27

so it is possible to create dynamic labels, but the issue is that it is picking up only last item from the repeating group.