victoriametrics-query
Original:🇺🇸 English
Translated
Query VictoriaMetrics metrics via curl. Use when running PromQL/MetricsQL queries, discovering metrics/labels, checking alerts and rules, inspecting TSDB status, exporting raw data, checking metric usage statistics, or debugging relabeling/downsampling/retention configs. Triggers on: metric queries, PromQL, MetricsQL, label discovery, series exploration, cardinality checks, alert status, recording rules, active/top queries, export data, metric statistics, relabel debug, downsampling debug, retention debug, flags.
95installs
Sourcevictoriametrics/skills
Added on
NPX Install
npx skill4agent add victoriametrics/skills victoriametrics-queryTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →VictoriaMetrics Metrics Query
Query VictoriaMetrics HTTP API directly via curl. Covers instant/range queries, label/series discovery, alerts, rules, instance diagnostics, raw data export, metric usage statistics, and config debugging tools.
Environment
bash
# $VM_METRICS_URL - base URL
# cluster: export VM_METRICS_URL="https://vmselect.example.com/select/0/prometheus"
# single: export VM_METRICS_URL="http://localhost:8428"
# $VM_AUTH_HEADER - auth header (set for prod, empty for local)Auth Pattern
All curl commands use conditional auth — works for both prod and local:
bash
curl -s ${VM_AUTH_HEADER:+-H "$VM_AUTH_HEADER"} "$VM_METRICS_URL/api/v1/query?query=up" | jq .When is empty, flag is omitted automatically.
VM_AUTH_HEADER-HCore Endpoints
Instant Query
bash
# Query at current time
curl -s ${VM_AUTH_HEADER:+-H "$VM_AUTH_HEADER"} \
"$VM_METRICS_URL/api/v1/query?query=up" | jq .
# Query at specific time
curl -s ${VM_AUTH_HEADER:+-H "$VM_AUTH_HEADER"} \
"$VM_METRICS_URL/api/v1/query?query=up&time=2026-03-07T09:00:00Z" | jq .Parameters: (required), (optional, RFC3339 or Unix seconds), ,
querytimesteptimeoutRange Query
bash
curl -s ${VM_AUTH_HEADER:+-H "$VM_AUTH_HEADER"} \
"$VM_METRICS_URL/api/v1/query_range?query=rate(http_requests_total[5m])&start=2026-03-07T00:00:00Z&end=2026-03-07T12:00:00Z&step=5m" | jq .Parameters: (required), (required), (optional), (required). Times in RFC3339 or Unix seconds.
querystartendstepLabels Discovery
bash
# All label names
curl -s ${VM_AUTH_HEADER:+-H "$VM_AUTH_HEADER"} \
"$VM_METRICS_URL/api/v1/labels" | jq '.data[]'
# Label values (label_name is a PATH parameter)
curl -s ${VM_AUTH_HEADER:+-H "$VM_AUTH_HEADER"} \
"$VM_METRICS_URL/api/v1/label/namespace/values" | jq '.data[]'
# Label values filtered by series matcher
curl -s ${VM_AUTH_HEADER:+-H "$VM_AUTH_HEADER"} \
--data-urlencode 'match[]={job="kubelet"}' \
"$VM_METRICS_URL/api/v1/label/namespace/values" | jq '.data[]'Series Discovery
bash
# Find series matching selector
curl -s ${VM_AUTH_HEADER:+-H "$VM_AUTH_HEADER"} \
--data-urlencode 'match[]={namespace="myapp"}' \
"$VM_METRICS_URL/api/v1/series?limit=20" | jq '.data[].__name__'Parameters: (required), , ,
match[]startendlimitMetric Metadata
bash
# Search by metric name keyword
curl -s ${VM_AUTH_HEADER:+-H "$VM_AUTH_HEADER"} \
"$VM_METRICS_URL/api/v1/metadata?metric=http_request&limit=10" | jq .Parameters: (search keyword), .
metriclimitAlerts and Rules
bash
# All firing/pending alerts
curl -s ${VM_AUTH_HEADER:+-H "$VM_AUTH_HEADER"} \
"$VM_METRICS_URL/api/v1/alerts" | jq '.data.alerts[]'
# All alerting and recording rules
curl -s ${VM_AUTH_HEADER:+-H "$VM_AUTH_HEADER"} \
"$VM_METRICS_URL/api/v1/rules" | jq '.data.groups[]'Instance Diagnostics
bash
# TSDB cardinality stats
curl -s ${VM_AUTH_HEADER:+-H "$VM_AUTH_HEADER"} \
"$VM_METRICS_URL/api/v1/status/tsdb" | jq .
# Currently executing queries
curl -s ${VM_AUTH_HEADER:+-H "$VM_AUTH_HEADER"} \
"$VM_METRICS_URL/api/v1/status/active_queries" | jq .
# Most frequent/slowest queries
curl -s ${VM_AUTH_HEADER:+-H "$VM_AUTH_HEADER"} \
"$VM_METRICS_URL/api/v1/status/top_queries?topN=10" | jq .
# Version info
curl -s ${VM_AUTH_HEADER:+-H "$VM_AUTH_HEADER"} \
"$VM_METRICS_URL/api/v1/status/buildinfo" | jq .Export Raw Data
bash
# Export raw samples as JSON lines (one JSON object per line)
curl -s ${VM_AUTH_HEADER:+-H "$VM_AUTH_HEADER"} \
--data-urlencode 'match[]=http_requests_total' \
-d 'start=2026-03-07T00:00:00Z' -d 'end=2026-03-07T12:00:00Z' \
"$VM_METRICS_URL/api/v1/export" | head -5
# Export with reduced memory usage (for large exports)
curl -s ${VM_AUTH_HEADER:+-H "$VM_AUTH_HEADER"} \
--data-urlencode 'match[]={namespace="myapp"}' \
-d 'start=2026-03-07T00:00:00Z' -d 'end=2026-03-07T01:00:00Z' \
-d 'reduce_mem_usage=1' \
"$VM_METRICS_URL/api/v1/export" > export.jsonlParameters: (required), , , . Output is JSON lines (not wrapped in a standard API response).
match[]startendreduce_mem_usageEach line:
{"metric":{"__name__":"...","label":"value"},"values":[...],"timestamps":[...]}Also available: (CSV format), (binary, for import via ).
/api/v1/export/csv/api/v1/export/native/api/v1/import/nativeSeries Count
bash
# Total number of active time series
curl -s ${VM_AUTH_HEADER:+-H "$VM_AUTH_HEADER"} \
"$VM_METRICS_URL/api/v1/series/count" | jq .Note: can be slow on large databases and may return slightly inflated values.
Metric Usage Statistics
bash
# Which metrics are being queried, and how often
curl -s ${VM_AUTH_HEADER:+-H "$VM_AUTH_HEADER"} \
"$VM_METRICS_URL/api/v1/status/metric_names_stats?limit=20" | jq .
# Metrics queried <= N times (find unused/rarely-used metrics)
curl -s ${VM_AUTH_HEADER:+-H "$VM_AUTH_HEADER"} \
"$VM_METRICS_URL/api/v1/status/metric_names_stats?limit=50&le=1" | jq .
# Filter by metric name pattern
curl -s ${VM_AUTH_HEADER:+-H "$VM_AUTH_HEADER"} \
"$VM_METRICS_URL/api/v1/status/metric_names_stats?match_pattern=vm_&limit=20" | jq .Parameters: (max results), (max query count threshold — find metrics queried at most N times), (metric name prefix filter).
limitlematch_patternFlags (Non-Default)
bash
# View non-default runtime flags (returns plain text, one flag per line — NOT JSON)
curl -s ${VM_AUTH_HEADER:+-H "$VM_AUTH_HEADER"} \
"${VM_METRICS_URL%%/select/*}/flags"Root-level endpoint. Returns plain text (not JSON), one flag per line. Shows only flags that differ from defaults — useful for debugging configuration.
Query Tools
These are ROOT-level endpoints, NOT under . On cluster mode, strip the prefix to get the base host.
/api/v1//select/0/prometheusbash
# Expand WITH expressions (returns text, not JSON)
curl -s ${VM_AUTH_HEADER:+-H "$VM_AUTH_HEADER"} \
"${VM_METRICS_URL%%/select/*}/expand-with-exprs?query=WITH(x=up)x"
# Prettify MetricsQL query (returns JSON)
curl -s ${VM_AUTH_HEADER:+-H "$VM_AUTH_HEADER"} \
"${VM_METRICS_URL%%/select/*}/prettify-query?query=rate(x[5m])" | jq .Note: strips everything from onward, yielding the base host. On single-node (local), has no prefix so it returns the URL unchanged.
${VM_METRICS_URL%%/select/*}/selectVM_METRICS_URL/selectConfig Debug Tools
Root-level endpoints for debugging relabeling, downsampling, and retention configurations. These accept POST with form data. Primarily used via VMUI but accessible via curl.
bash
# Debug metric relabeling rules — test how a metric is transformed
curl -s ${VM_AUTH_HEADER:+-H "$VM_AUTH_HEADER"} \
-d 'metric=foo{bar="baz"}' \
-d 'relabel_config=- target_label: cluster
replacement: dev' \
"${VM_METRICS_URL%%/select/*}/metric-relabel-debug"
# Debug downsampling filters — test which downsampling rules match a metric
curl -s ${VM_AUTH_HEADER:+-H "$VM_AUTH_HEADER"} \
-d 'metric=foo{bar="baz"}' \
-d 'downsampling_period=30d:5m,180d:1h' \
"${VM_METRICS_URL%%/select/*}/downsampling-filters-debug"
# Debug retention filters — test which retention policy applies to a metric
curl -s ${VM_AUTH_HEADER:+-H "$VM_AUTH_HEADER"} \
-d 'metric=foo{bar="baz"}' \
-d 'retention_period=2y,{env="dev"}:30d' \
"${VM_METRICS_URL%%/select/*}/retention-filters-debug"These return HTML by default. For programmatic use, the VMUI at provides an interactive interface.
${VM_METRICS_URL%%/select/*}/vmui/#/relabelingTimestamp Format
All times accept RFC3339 () or Unix seconds (). Default for instant queries is "now". Default for range queries is "now".
2026-03-07T09:00:00Z1709769600timeendResponse Parsing (jq)
bash
# Extract metric values from instant query
... | jq '.data.result[] | {metric: .metric.__name__, value: .value[1]}'
# Extract time series from range query
... | jq '.data.result[] | {metric: .metric, values: [.values[] | {time: .[0], value: .[1]}]}'
# List metric names from series response
... | jq '[.data[] | .__name__] | unique'
# Count alerts by state
... | jq '.data.alerts | group_by(.state) | map({state: .[0].state, count: length})'
# Top series by cardinality from tsdb status
... | jq '.data.seriesCountByMetricName[:10]'Common Patterns
bash
# Check if a metric exists
curl -s ${VM_AUTH_HEADER:+-H "$VM_AUTH_HEADER"} \
"$VM_METRICS_URL/api/v1/query?query=count({__name__=~\"http_request.*\"})" | jq '.data.result[].value[1]'
# Get all namespaces with active pods
curl -s ${VM_AUTH_HEADER:+-H "$VM_AUTH_HEADER"} \
--data-urlencode 'match[]={__name__="kube_pod_info"}' \
"$VM_METRICS_URL/api/v1/label/namespace/values" | jq '.data[]'
# Rate of errors over last hour
curl -s ${VM_AUTH_HEADER:+-H "$VM_AUTH_HEADER"} \
--data-urlencode 'query=sum(rate(http_requests_total{code=~"5.."}[5m])) by (namespace)' \
"$VM_METRICS_URL/api/v1/query" | jq '.data.result[] | {ns: .metric.namespace, rate: .value[1]}'Environment Switching
bash
# Check current environment
echo "VM_METRICS_URL: $VM_METRICS_URL"
echo "VM_AUTH_HEADER: $( [ -n "$VM_AUTH_HEADER" ] && echo '(set)' || echo '(empty)' )"Important Notes
- POST endpoints accept (use
application/x-www-form-urlencodedfor query params with special chars)--data-urlencode - parameter requires the
match[]suffix —[]alone won't workmatch - For metric metadata, raw API uses param
metric - uses a path parameter:
label_values/api/v1/label/{label_name}/values - ,
expand-with-exprs,prettify-query,flags,metric-relabel-debug, anddownsampling-filters-debugare root-level paths, not underretention-filters-debug/api/v1/ - Export endpoint () returns JSON lines (one object per line), not standard API response JSON
/api/v1/export - Debug endpoints (, etc.) return HTML by default — best used via VMUI for interactive debugging
metric-relabel-debug - For full endpoint details, parameters, and response formats, see
references/api-reference.md