Prometheus's expression language data types
<expression> := <metric_name>{<label_selectors>} <operator> <aggregation/functions>
Instant vector
- A
set of time seriescontaining asingle sample(datapoints) for each time series, evaluated at the a evaluation time ("now" if omitted) - The engine looks backward from the evaluation time and returns
that series' most recent samplewithin the lookback window (default 5m)
services_http_requests_total{service="ronaldo",path="/api/version"}
{
"metric": {
"__name__": "services_http_requests_total",
"aws_region": "us-east-2",
"environment": "prod",
"kubernetes_pod_name": "ronaldo-5975f7c77d-7kktn",
"method": "get",
"path": "/api/version",
"service": "ronaldo",
"status": "200",
},
"value": [
1783977321, "1576"
]
},
Range vector
- A
set of time seriescontaining aset of samples(datapoints) for each time series over a period of time - Range vectors exists so that functions can consume a window of raw data and these functions need a set of raw samples to operate on
-
The real job of range vectors is almost always to be immediately wrapped in a function (rate(), increase(), avg_over_time(), sum_over_time())
-
This is different from a range query (
query_rangeAPI): the range vector syntax has nostepconcept and returns every raw stored sample in the window with its original scrape timestamp.query_rangeinstead re-evaluates at eachstepgrid point, keeping only the sample nearest each step (silently dropping others that fall between two steps) and stamping the result with the step timestamp, not the real sample timestamp. -
When a bare range vector expression is sent to
query_rangedirectly, vicmetrics will automatically wrap it in adefault_rollup()
rate(services_http_requests_total{service="ronaldo",path="/api/version"}[5m])
{
"metric": {
"__name__": "services_http_requests_total",
"aws_region": "us-east-2",
"environment": "prod",
"kubernetes_pod_name": "prod-global-blue-ronaldo-deployment-5975f7c77d-7kktn",
"method": "get",
"path": "/api/version",
"service": "ronaldo",
"status": "200",
},
"values": [
[ 1783978236, "1762" ],
[ 1783978251, "1768" ],
[ 1783978266, "1768" ],
[ 1783978281, "1774" ],
[ 1783978296, "1774" ],
[ 1783978311, "1780" ],
[ 1783978326, "1780" ],
[ 1783978341, "1786" ],
[ 1783978356, "1786" ],
[ 1783978371, "1792" ],
[ 1783978386, "1792" ],
[ 1783978401, "1798" ],
[ 1783978416, "1798" ],
[ 1783978431, "1804" ],
[ 1783978446, "1804" ],
[ 1783978461, "1810" ],
[ 1783978476, "1810" ],
[ 1783978491, "1816" ],
[ 1783978506, "1816" ],
[ 1783978521, "1816" ],
[ 1783978536, "1816" ]
]
},
ms # milliseconds
s # seconds
m # minutes
h # hours
d # days - assuming a day has always 24h
w # weeks - assuming a week has always 7d
y # years - assuming a year has always 365d
1h30m
Scalar
- Float literals
- A single floating point number (no labels)
23
-2.43
3.4e-9
0x8f
-Inf
NaN
String
- String literal
- Used in limited string-processing functions like label_replace()
- Defined with quotes, double quotes or backticks
"this is a string"
'these are unescaped: \n \\ \t'
`these are not unescaped: \n ' " \t`