Hi everyone,
I’m evaluating Loki for analyzing log files right now and have problems parsing the datetime that’s part of an apache access log line.
The log line looks something like that (ip address changed):
10.11.12.0 - - [28/Jan/2020:00:27:21 +0100] "GET / HTTP/1.1" 200 2963 "-" "worldping-api"
My regex looks like this:
- regex:
expression: '(?P<clientAddr>\w{1,3}.\w{1,3}.\w{1,3}.\w{1,3}) - - .(?P<timestamp>\d{2}.*\d{4}). "(?P<request>.*)" (?P<code>\d+) .* "(?P<referrer>.*)" "(?P<client>.*)"'
This seems to work; when setting up labels for all those matches they show up in Grafana explorer, and the timestamp
field contains 28/Jan/2020:18:29:22 +0100
.
But Promtail doesn’t seem to parse the datetime correctly, since in Grafana each log entry shows up with the time of when it was recorded (which doesn’t correlate to when the request was made, since the logs are written to the file with a delay).
I setup a timestamp parser like this:
- timestamp:
source: timestamp
format: "02/Jan/2006:03:04:05 -0700"
I don’t have much Go experience, but tried to setup the format string according to the time.Parse
docs and validate it with http://gotime.agardner.me/parser.html – according to this, the format string should be allright.
Can somebody give me a hint about why this could not work and how to improve it?
Best,
Benjamin.
For reference, my whole pipeline stage looks like this:
pipeline_stages:
- match:
selector: '{filename="/home/alu/logs/access_log"}'
stages:
- regex:
expression: '(?P<clientAddr>\w{1,3}.\w{1,3}.\w{1,3}.\w{1,3}) - - .(?P<timestamp>\d{2}.*\d{4}). "(?P<request>.*)" (?P<code>\d+) .* "(?P<referrer>.*)" "(?P<client>.*)"'
- labels:
clientAddr:
request:
code:
referrer:
client:
timestamp:
- timestamp:
source: timestamp
format: "02/Jan/2006:03:04:05 -0700"