Skip to content

Instantly share code, notes, and snippets.

@ruanbekker
Last active November 5, 2024 13:45
Show Gist options
  • Save ruanbekker/cb4ebdc24331661ca120f20b4445ad75 to your computer and use it in GitHub Desktop.
Save ruanbekker/cb4ebdc24331661ca120f20b4445ad75 to your computer and use it in GitHub Desktop.
Loki Regex LogQL Query for Nginx Access Logs

Access Log:

172.16.4.86 - - [04/Jun/2022:07:58:38 +0000] "GET / HTTP/2.0" 301 280 "-" "curl"

Query in Grafana / Loki:

{job="prod/nginx"} |= "GET / " 
| regexp `(?P<ip>\S+) (?P<identd>\S+) (?P<user>\S+) \[(?P<timestamp>[\w:\/]+\s[+\\-]\d{4})\] "(?P<action>\S+)\s?(?P<path>\S+)\s?(?P<protocol>\S+)?" (?P<status>\d{3}|-) (?P<size>\d+|-)\s?"?(?P<referrer>[^\"]*)"?\s?"?(?P<useragent>[^\"]*)?"?`

More examples:

References:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment