-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Docs: improve LogQL section - Add a subsection for examples - Fix typos and wording * Update docs/sources/logql/query_examples.md Co-authored-by: Sandeep Sukhani <[email protected]> * Update docs/sources/logql/query_examples.md Co-authored-by: Sandeep Sukhani <[email protected]> Co-authored-by: Owen Diehl <[email protected]> Co-authored-by: Sandeep Sukhani <[email protected]>
- Loading branch information
1 parent
10c92a9
commit 368d18c
Showing
3 changed files
with
69 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
--- | ||
title: Query examples | ||
weight: 40 | ||
--- | ||
|
||
# Query examples | ||
|
||
Some useful query examples here. | ||
|
||
## Log Query examples | ||
|
||
### Examples that filter on IP address | ||
|
||
- Return log lines that are not within a range of IPv4 addresses: | ||
|
||
```logql | ||
{job_name="myapp"} != ip("192.168.4.5-192.168.4.20") | ||
``` | ||
- This example matches log lines with all IPv4 subnet values `192.168.4.5/16` except IP address `192.168.4.2`: | ||
```logql | ||
{job_name="myapp"} | ||
| logfmt | ||
| addr = ip("192.168.4.5/16") | ||
| addr != ip("192.168.4.2") | ||
``` | ||
### Examples that aid in security evaluation | ||
- Extract the user and IP address of failed logins from Linux `/var/log/secure` | ||
```logql | ||
{job="security"} | ||
|~ "Invalid user.*" | ||
| regexp "(^(?P<user>\\S+ {1,2}){8})" | ||
| regexp "(^(?P<ip>\\S+ {1,2}){10})" | ||
| line_format "IP = {{.ip}}\tUSER = {{.user}}" | ||
``` | ||
- Get successful logins from Linux `/var/log/secure` | ||
```logql | ||
{job="security"} | ||
!= "grafana_com" | ||
|= "session opened" | ||
!= "sudo: " | ||
|regexp "(^(?P<user>\\S+ {1,2}){11})" | ||
| line_format "USER = {{.user}}" | ||
``` | ||
## Metrics Query examples | ||
- Return the per-second rate of all non-timeout errors | ||
within the last minutes per host for the MySQL job, | ||
and only include errors whose duration is above ten seconds. | ||
``` | ||
sum by (host) (rate({job="mysql"} | ||
|= "error" != "timeout" | ||
| json | ||
| duration > 10s [1m])) | ||
``` |