LogQL in Grafana Loki
Now that we have a Loki data source we can query it with the LogQL query language.
In this video, we will try out many LogQL queries on the Loki data source we’ve setup.
There are two types of LogQL queries:
- Log queries returning the contents of log lines as streams.
- Metric queries that convert logs into value matrixes.
A LogQL query consists of,
- The log stream selector
- Filter expression
We can use operations on both the log stream selectors and filter expressions to refine them.
Log Stream Selectors
Operators
- = : equals
- != : not equals
- =~ : regex matches
- !~ : regex does not match
EXAMPLES
Return all log lines for the job varlog
{job="varlogs"}
Return all log lines for the filename /var/log/syslog
{filename="/var/log/syslog"}
Return all log lines for the job varlogs
and the filename /var/log/auth.log
{filename="/var/log/auth.log",job="varlogs"}
Show all log lines for 2 jobs with different names
{filename=~"/var/log/auth.log|/var/log/syslog"}