-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Promtail: Cant get the value of filename in relabel_configs #775
Comments
same problem here scrapeConfigs:
- job_name: logs
entry_parser: raw
static_configs:
- targets:
- localhost
labels:
__path__: /var/log/services/*/service.log
relabel_configs:
- source_labels:
- filename
target_label: 'service'
regex: '(services)\/?([^\/]+)\/'
replacement: '$2' |
You should try See: https://github.com/grafana/loki/blob/master/docs/troubleshooting.md#troubleshooting-targets |
I tried with
|
ok the expansion of the I'm switching this issue to a feature request, PR are welcome :). |
Actually you should use the pipeline stages instead that would be easier for you, to extract service from filename. see: https://github.com/grafana/loki/blob/master/docs/logentry/processing-log-lines.md |
I tried to configure pipeline stage, but it doesn't work.
PS:
|
So far, what i know is that the pipeline stage can only process the log entry. |
It can also process labels after discovery and relabeling |
This issue has been automatically marked as stale because it has not had any activity in the past 30 days. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. |
@cyriltovena Working on this. Will create a PR soon. |
@adityacs can you document how to use the I have this:
The idea is to add a label (first_dir) with the name of the first directory of the path. |
You need to add the label path as a source for the regex stage otherwise it parses the log line not the label. See https://github.com/grafana/loki/blob/master/docs/clients/promtail/stages/regex.md#schema |
@rmgpinto I was trying to do roughly the same thing. I was able to get labels created from
|
Any idea how that would work when using
We do not see any logs, but if we remove the |
You need the regex see this example: https://gist.github.com/cyriltovena/7cc5359a692206782db889f4c73f78b1 |
Thanks, we tried it before and it was not working - but actually the issue was that we did not properly escape the regex when using double quotes. Using single quotes and the following config works:
|
Trying to get this working to have Promtail drop it's own logs on Nomad:
|
So the PR is merged... can anybody post here the working example of extracting filename to custom label? scrape_configs:
- job_name: logs
entry_parser: raw
static_configs:
- targets:
- localhost
labels:
__path__: /var/log/services/*/service.log
relabel_configs:
- source_labels: ["__path__"]
target_label: 'my_custom_label' As result I see in |
try this :
|
@petrukngantuk Thanks! Worked for me with a little modification: scrape_configs:
- job_name: logs
static_configs:
- targets:
- localhost
labels:
job: service-log
__path__: /home/ubuntu/log/*/*[^0-9].log
pipeline_stages:
- match:
selector: '{job="service-log"}'
stages:
- regex:
source: filename
expression: "/home/ubuntu/log/(?P<service>\\S+?)/"
- labels:
service: with log files like: /home/ubuntu/log/service-name/service-name.log
/home/ubuntu/log/service-name/service-name.2021.01.01.log |
In relabel_configs, I would like to get the filename label value to rewrite to a specific label.
For instance, there are some log files in the directory.
I expect set a label called "service" equal to "example"
Then, I have the setting below in the relabel_configs of promtail
I have tested "filename" and "path" into the source_labels.
There is no value return when source_labels set to "filename".
When the source_label set to "path", the value equals to "/logs/*.log"
How can i get the correct file path in relabel_configs?
The text was updated successfully, but these errors were encountered: