I am trying to label all logs that come out of a folder with the name of the folder. This is my current config. Basically I want the logs to be labeled with the name of the * value. I’ve tried different regex methods i’ve found but anything I try keeps Grafana Agent service from starting.
logs:
positions_directory: C:\ProgramData\grafana-agent\log-positions
configs:
- name: default
positions:
filename: /tmp/positions.yaml
scrape_configs:
- job_name: BackgroundIndexer
static_configs:
- targets:
- localhost
labels:
job: BackgroundIndexer
__path__: L:\BackgroundIndexer\*\*.txt
Resolved it with help from this link
opened 11:33AM - 18 Jul 19 UTC
closed 01:00PM - 10 Oct 19 UTC
component/agent
component/integrations
kind/question
keepalive
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.
- /logs/example-out.log
- /logs/example-error.log
I expect set a label called "service" equal to "example"
Then, I have the setting below in the relabel_configs of promtail
```yaml
static_configs:
- targets:
- localhost
labels:
job: test
__path__: /logs/*.log
relabel_configs:
- source_labels: [filename]
regex: '^.*\/(.+)-(out|error)\.log$'
replacement: '${1}'
target_label: service
action: replace
```
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?
logs:
positions_directory: C:\ProgramData\grafana-agent\log-positions
configs:
- name: default
positions:
filename: /tmp/positions.yaml
scrape_configs:
- job_name: BackgroundIndexer
static_configs:
- targets:
- localhost
labels:
job: BackgroundIndexer
__path__: L:\BackgroundIndexer\*\*
pipeline_stages:
- match:
selector: '{job="BackgroundIndexer"}'
stages:
- regex:
source: filename
expression: 'L:\\BackgroundIndexer\\(?P<customer>[^\\]+)\\'
- labels:
customer:
1 Like