Hi,
I am using promtail to scrape logs and I want to get the client (name), server, service and log file name from the path.
Then I want based on the service, extract the timestamp from the log so that loki doesnt load data using the current time stamp.
This is my config in promtail, something wrong?
scrape_configs:
- job_name: system
static_configs:
- targets:
- Europa
labels:
job: system-logs
__path__: /var/log/*log
- job_name: 'client-logs'
static_configs:
- targets:
- Europa
labels:
job: 'client-logs'
__path__: /data/ingester/*/*/*/* # Match all log files, adjust path as needed
relabel_configs:
- source_labels: ["__path__"]
regex: /data/ingester/([^/]+)/([^/]+)/([^/]+)/(.*)
replacement: $1
target_label: client
action: replace
- source_labels: ["__path__"]
regex: /data/ingester/([^/]+)/([^/]+)/([^/]+)/(.*)
replacement: $2
target_label: server
action: replace
- source_labels: ["__path__"]
regex: /data/ingester/([^/]+)/([^/]+)/([^/]+)/(.*)
replacement: $3
target_label: service
action: replace
- source_labels: ["__path__"]
regex: /data/ingester/([^/]+)/([^/]+)/([^/]+)/(.*)
replacement: $4
target_label: logfile
action: replace
pipeline_stages:
- match:
selector: '{logfile=~"_gc"}'
stages:
- regex:
expression: '^\[(?P<time>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\S+[-+]\d{4})\]\[\S+\]\[\S+\]\[(?P<level>\S+)\].+'
- labels:
time:
level:
- timestamp:
source: time
format: "2006-01-02T15:04:05.000-0700"
- match:
selector: '{logfile=~"coref"}'
stages:
- regex:
expression: '^(?P<time>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\S+) - (?P<level>\S+).+'
- labels:
time:
level:
- timestamp:
source: time
format: "2006-01-02 15:04:05,000"
- match:
selector: '{service=~"service|web|engine|integration|user"}'
stages:
- regex:
expression: '^(?P<time>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\S+) (?P<level>\S+).+'
- labels:
time:
level:
- timestamp:
source: time
format: "2006-01-02 15:04:05,000"
- match:
selector: '{logfile=~"mysqld"}'
stages:
- regex:
expression: '^(?P<time>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{6}Z) \d+ \[(?P<level>\S+)\].+'
- labels:
time:
level:
- timestamp:
source: time
format: "2006-01-02T15:04:05.000000Z"
- match:
selector: '{logfile=~"haproxy"}'
stages:
- regex:
expression: '^(?P<time>\S+\s+\d{1,2}\s\d{2}:\d{2}:\d{2}).+'
- labels:
time:
level:
- timestamp:
source: time
format: "Jan 9 03:10:03"
- match:
selector: '{logfile="messages"}'
stages:
- regex:
expression: '^(?P<time>\S+\s+\d{1,2}\s\d{2}:\d{2}:\d{2}).+'
- labels:
time:
level:
- timestamp:
source: time
format: "Jan 9 03:10:03"
I hope you can find something wrong in the config. I dont see an error in promtail log, it just send data to loki without taking care of the timestamp and none the labels i defined are used.
Here is an example with mysql log. Logs are loaded but the time is the received time, not the time from the log itself. Is it possible to make promtail send the log timestamp to loki/grafana?
Thanks for your help in advance.