Hello,
I’m discovering Grafana, Loki and Promtail to process my Apache and Nginx logs.
I have created this pipeline_stages which works well to define the level
label depending on the value of http_code
:
pipeline_stages:
- match:
selector: '{job="apache"}'
stages:
- regex:
expression: '^\S+ \S+ \S+ \S+ \S+ \S+ \S+ \[.+\] "\S+ \S+ \S+" (?P<http_code>\d{3}) \S+ "[^"]*" "[^"]*" \S+ \S+ In:\S+ Out:.+:.+pct. \S+$'
- labels:
http_code:
- match:
selector: '{job="apache", http_code=~"(2|3)\\d{2}"}'
stages:
- static_labels:
level: 'info'
- match:
selector: '{job="apache", http_code=~"4\\d{2}"}'
stages:
- static_labels:
level: 'warn'
- match:
selector: '{job="apache", http_code=~"5\\d{2}"}'
stages:
- static_labels:
level: 'crit'
At present, I have to create the http_code
label on the first part to be able to match the static_labels afterwards.
Is it possible to optimize my pipeline_stages so that :
- I specify my regex only once, as at present
- I don’t export the http_code label
- My selectors for defining the value of my static_labels can retrieve the value of http_code directly from the regex
My aim is to try and lighten processing as much as possible by avoiding unnecessary label exports for loki, and to group processing.
Thank your for your help!