Skip to content

Instantly share code, notes, and snippets.

@ruanbekker
Last active January 22, 2024 07:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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