Enterprise version of VictoriaMetrics supports statistics logging
Available from the next release
for
executed read queries for /api/v1/query
and /api/v1/query_range API. To enable statistics
logging specify -search.logSlowQueryStats=<duration>
command line flag on vmselect
or Single-node VictoriaMetrics.
Where <duration>
is a threshold for query duration after which it must be logged:
-search.logSlowQueryStats=5s
will log stats for queries with execution duration exceeding5s
;-search.logSlowQueryStats=1us
will log stats all queries;-search.logSlowQueryStats=0
disables stats logging.
The example of query statistics log is the following:
|
|
type
is either instant or range query;query
is the executed MetricsQL query;query_hash
is a hashedquery
and is used to simplify filtering logs by a specific query;start_ms
,end_ms
,step_ms
are query params described here;range_ms
is a difference betweenstart_ms
andend_ms
. Ifrange_ms==0
it means this query is instant;tenant
is a tenant ID. Is available only for cluster version of VictoriaMetrics;execution_duration_ms
is execution duration of the query. It doesn’t include time spent on transferring query results to the requester over network;series_fetched
is the amount of unique time series fetched during query execution. The number could be bigger than the actual number of returned series, as it accounts for series before filtering by bool conditions (likecpu_usage > 0
);samples_fetched
is the amount of data samples fetched during query execution;bytes
is the amount of bytes transferred from storage to execute the query;memory_estimated_bytes
is the estimated amount of memory that is needed to evaluate query. See-search.maxMemoryPerQuery
cmd-line flag.
Analysis #
It is recommended to collect query statistics logs into VictoriaLogs for the post-analysis of the query performance.
The generated statistics logs are prefixed with vm_slow_query_stats
key word to simplify filtering. All the logged fields
are formatted in logfmt format to simplify the parsing.
For example, once these logs are available in VictoriaLogs for querying, the following query will find top 5 slowest queries:
|
|
Here, we begin query with vm_slow_query_stats
to filter only logs that have the key word.
Then, with extract 'vm_slow_query_stats <query_stats>' | unpack_logfmt from query_stats
we extract and parse log message
into separate fields. And now we can calculate various stats:
|
|
or
|
|
With VictoriaLogs Grafana datasource we can build a dashboard with various stats and query filtering options:

The example of Grafana datasource is available here.