Documentation for automated readers
A curated documentation index is available at: https://grafana.com/llms.txt
A complete documentation index is available at: https://grafana.com/llms-full.txt
These indexes can help with page discovery before fetching individual documents.
This page is also available in Markdown, which may be easier for automated readers and AI tools to parse than HTML. The Markdown version is available at https://grafana.com/docs/grafana-cloud/machine-learning/sift/analyses/metric-query.md, or by sending Accept: text/markdown to https://grafana.com/docs/grafana-cloud/machine-learning/sift/analyses/metric-query/. For broader documentation discovery, the curated index is available at https://grafana.com/llms.txt and the complete index is available at https://grafana.com/llms-full.txt.
Sift analysis - Metric query
This analysis runs a custom Prometheus query configured by the user and uses the result to populate a configurable template.
Inputs
Required:
- None
Optional:
- Custom filters
How it works
Step 1: Process query
Interpolates the user’s query using the investigation labels.
For example: node_load1{namespace=”$namespace”, cluster=”$cluster”} becomes node_load1{namespace=”machine-learning”, cluster=”dev-us-central-0”}
Step 2: Execute query
Executes the query against the discovered Prometheus datasource.
Step 3: Process results
Interpolates the template message using the result of the query.
For example, this template:
I found something interesting!
Expr: {{ .expr }}
{{ range .series -}}
Series: {{ .Labels }}
* Last Timestamp: {{ .LastTimestamp.UTC.Format "2006-01-02T15:04:05Z07:00" }}
* Last Value: {{ .LastValue }}
{{ end -}}Becomes this result:
I found something interesting!
Expr: node_load1{namespace=”machine-learning”, cluster=”dev-us-central-0”}
Series: {foo="bar"}
* Last Timestamp: 1970-01-01T00:00:00Z
* Last Value: 0
Series: {foo="baz"}
* Last Timestamp: 2023-04-06T15:39:27Z
* Last Value: 1What resources does this analysis use?
- Prometheus datasource
How does this analysis determine when a result is interesting?
- If at least one series is returned by the query, the check is considered interesting.
What configurations options are available for this analysis?
Query
The custom PromQL query expression to run.
Message template
A Go template string used to format the output of the check.
The template string has access to the following variables:
expr: the input expression stringinteresting: a boolean indicating whether this check found any interesting resultsseries: an array of time series. Each element has three fields:Labels, a Prometheus Metric implemented as a map from label name to label value used to identify the series.LastTimestamp, the latest timestamp found in the input query.LastValue, the latest value found in the input query.
Was this page helpful?
Related resources from Grafana Labs


