-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow mutations on data #36
Comments
|
Thanks for the feature request. I think it's a good idea. I will look into it. Apart from that: The cases you describe (only keep base url, extract query string labels) can also be achieved with a grok pattern. |
Thanks for the positive reply, happy to hear that you find the idea is relevant :) I knew adapting the line matching regex could help for some mutations but for the query string problem I cannot see how would it works for matching all query strings (and name them accordingly). Bonus: Decode URL encoded query strings value cannot be done using regex matching ;) Disclosure: I'll pair logstash to grok_exporter for now (logstash will ingest file, mutate it and feed it to grok_exporter), but as soon as I can drop logsatsh and perform my mutations directly into grok_exporter I will :) Other disclosure: I opened a similar feature request on |
I implemented an experimental Example: If labels:
id: '{{gsub .url ".*id=([^&]*).*" "\\1"}}' The syntax is The pattern and replacement syntax is similar to Elastic's mutate filter's gsub (derived from Ruby's String.gsub()), except that you need to double-escape backslashes (\\ instead of \). In the example, Let me know if this is helpful. |
Great! This is very helpful to us, do you plans to release this? Thanks in advance! |
Done. Rel v0.2.6. Documentation still needs to be updated though. |
Documentation updated. |
Can you please explain how can I transform text strings than contains "True" and "False" to boolean metrics with "gsub"? |
You should use conditionals for that instead of grok:
additional_patterns:
- 'BOOLEAN True|False'
metrics:
- type: gauge
name: boolean_test
help: boolean test
match: '%{BOOLEAN:bool}'
value: '{{if eq .bool "True"}}1{{else}}0{{end}}' |
Thanks a lot! |
@fstab please add the following as an example to the documentation where you feel it's appropriate. I'm using it to convert units of measurement to base units (e.g. GB to bytes):
The tricky part is - I'm maintaining the config files from ansible, and I need to escape every '{{' and '}}' and it looks awful... Any suggestions on forcing a different separator? :) |
@fstab I was able to get a constant value from my logfile and set it to gauge metric , but I want it to be updated every time with latest value. |
TL;DR: Create new fields from other fields (or replace values of existing ones) via regex or other builtin fonctions, just like
logstash
'smutate
plugin.Context: I've just dicsovered this tool (and
mtail
) after trying to perform tail+parse+count data processing in existing PHP application (disclaimer: it failed).grok_exporter
seems great but there is one feature I would miss: data mutations.The ability to alter fields before exporting to Prometheus (just like
logstash
'smutate
plugin) would be awesome.In my use case I am reading Apache access.log file and I want to export HTTP requests count with the following dimensions/labels:
http://example.com/foo.asp?id=42
=>http://example.com
): some regex would do (or I could adapt the line matching regex)http://example.com/foo.asp?id=42&source=github&foo=bar
I want the following fields (thus labels):id
andfoo
. I get that dropping labels is already somethinggrok_exporter
can do, so having a mutation that creates a label for every found query parameter is fine.Other use cases (not mine):
-
byconnected_user
and the-
value byguest
).The text was updated successfully, but these errors were encountered: