Converting timestamps to hh:ss
natural_message=/PROCESSING REQUEST method=.*/
| Time := format("%tH:%tM",field=[@timestamp,@timestamp])
| groupBy([Time], function=count(as="Number of Requests"))
| sort(field=Time, order=asc)
- Displays the timestamp as
hh:ss
e.g.08:29
in a new field calledTime
- Counts all logs with a matching
natural_message
and groups them byTime
in ascending order
Converting timestamps to dates
date := formatTime("%Y-%m-%d", field=@timestamp, locale=en_UK, timezone="GMT")
| groupBy([date])
| sort(field=date, order=desc)
- Displays the timestamp as
YYYY-MM-DD
- Counts logs and sorts them in descending order by newly created
date
Truncating fields
replace("^(.{25}).*", with="$1", field=field_to_truncate, as="new_name_of_field")
| groupBy([truncated_message])
^(.{25}).*
matches the first 25 characters of the field as a capturing groupwith="$1"
replaces entire content with the capturing group only i.e. the first 25 characters
Using capturing groups
Assume a field called natural_message
with the following values:
UserDetails(id=123, name=Jill, age=30)
Some other message
UserDetails(id=456, name=Jill, age=30)
natural_message=/(UserDetails.*(?<user_id>id=[0-9]+).*|.*name=(?<user_name>[A-z]+).*)/
| groupBy([user_name], function=count(as="user_count"))
UserDetails.*(?<user_id>id=[0-9]+).*
will return two capture both UserDetail logs and returnid={...}
.*name=(?<user_name>[A-z]+).*
will return all logs and return 2 xJill
i.e. without thename=
groupBy([user_name])
will return the result as two columnsuser_name
anduser_count
with a count of 2 forJill
Filtering fields by value
in(level, values=["ERROR", "WARN"])
- Filters the
level
field to onlyERROR
andWARN
values
Combining fields
format("%s@%s", field=[application, applicationVersion], as=Application)
- Combines the
application
andapplicationVersion
fields separated by@
into a new field calledApplication
Ordering by value
sort("price", order=desc)
Using parameters
environment=?environment
| application=?application
- Allows setting
application
andenvironment
in top bar (dashboards and individual searches)