2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								title: Querying basics
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								nav_title: Basics
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								sort_rank: 1
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-12-18 18:57:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								Prometheus provides a functional query language called PromQL (Prometheus Query
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Language) that lets the user select and aggregate time series data in real
							 
						 
					
						
							
								
									
										
										
										
											2025-05-29 03:37:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								time.
							 
						 
					
						
							
								
									
										
										
										
											2024-07-22 23:17:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								When you send a query request to Prometheus, it can be an _instant query_ , evaluated at one point in time,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								or a _range query_  at equally-spaced steps between a start and an end time. PromQL works exactly the same
							 
						 
					
						
							
								
									
										
										
										
											2025-09-02 19:44:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								in each case; the range query is just like an instant query run multiple times at different timestamps.
							 
						 
					
						
							
								
									
										
										
										
											2024-07-22 23:17:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								In the Prometheus UI, the "Table" tab is for instant queries and the "Graph" tab is for range queries.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Other programs can fetch the result of a PromQL expression via the [HTTP API ](api.md ).
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								## Examples
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-10 01:37:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								This document is a Prometheus basic language reference. For learning, it may be easier to
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								start with a couple of [examples ](examples.md ).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								## Expression language data types
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								In Prometheus's expression language, an expression or sub-expression can
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								evaluate to one of four types:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								*  **Instant vector** - a set of time series containing a single sample for each time series, all sharing the same timestamp 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								*  **Range vector** - a set of time series containing a range of data points over time for each time series 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								*  **Scalar** - a simple numeric floating point value 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								*  **String** - a simple string value; currently unused 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-09-02 19:44:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								Depending on the use case (e.g. when graphing vs. displaying the output of an
							 
						 
					
						
							
								
									
										
										
										
											2024-02-10 01:37:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								expression), only some of these types are legal as the result of a
							 
						 
					
						
							
								
									
										
										
										
											2025-05-29 03:37:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								user-specified expression.
							 
						 
					
						
							
								
									
										
										
										
											2024-10-03 20:11:44 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								For [instant queries ](api.md#instant-queries ), any of the above data types are allowed as the root of the expression.
							 
						 
					
						
							
								
									
										
										
										
											2024-11-24 19:37:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								[Range queries ](api.md#range-queries ) only support scalar-typed and instant-vector-typed expressions.
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-14 20:46:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								_Notes about the experimental native histograms:_
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								*  Ingesting native histograms has to be enabled via a [feature 
						 
					
						
							
								
									
										
										
										
											2024-08-30 01:36:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  flag](../feature_flags.md#native-histograms).
							 
						 
					
						
							
								
									
										
										
										
											2022-10-14 20:46:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								*  Once native histograms have been ingested into the TSDB (and even after 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  disabling the feature flag again), both instant vectors and range vectors may
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  now contain samples that aren't simple floating point numbers (float samples)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  but complete histograms (histogram samples). A vector may contain a mix of
							 
						 
					
						
							
								
									
										
										
										
											2024-12-13 06:54:15 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  float samples and histogram samples. Note that the term “histogram sample” in
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  the PromQL documentation always refers to a native histogram. Classic
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  histograms are broken up into a number of series of float samples. From the
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  perspective of PromQL, there are no “classic histogram samples”.
							 
						 
					
						
							
								
									
										
										
										
											2025-08-14 01:25:17 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								*  Like float samples, histogram samples can have a counter or a gauge “flavor”, 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  marking them as counter histograms or gauge histograms, respectively. In
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  contrast to float samples, histogram samples “know” their flavor, allowing
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  reliable warnings about mismatched operations (e.g. applying the `rate` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  function to a range vector of gauge histograms).
							 
						 
					
						
							
								
									
										
										
										
											2024-12-13 06:54:15 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								*  Native histograms can have different bucket layouts, but they are generally 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  convertible to compatible versions to apply binary and aggregation operations
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  to them. This is not true for all bucketing schemas. If incompatible
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  histograms are encountered in an operation, the corresponding output vector
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  element is removed from the result, flagged with a warn-level annotation.
							 
						 
					
						
							
								
									
										
										
										
											2025-08-14 01:25:17 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  More details can be found in the [native histogram
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  specification](https://prometheus.io/docs/specs/native_histograms/#compatibility-between-histograms).
							 
						 
					
						
							
								
									
										
										
										
											2022-10-14 20:46:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								## Literals
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								### String literals
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-10 01:37:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								String literals are designated by single quotes, double quotes or backticks.
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								PromQL follows the same [escaping rules as
							 
						 
					
						
							
								
									
										
										
										
											2024-02-10 01:37:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								Go](https://golang.org/ref/spec#String_literals). For string literals in single or double quotes, a
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								backslash begins an escape sequence, which may be followed by `a` , `b` , `f` ,
							 
						 
					
						
							
								
									
										
										
										
											2024-02-10 01:37:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								`n` , `r` , `t` , `v`  or `\` .  Specific characters can be provided using octal 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								(`\nnn`) or hexadecimal (`\xnn`, `\unnnn`  and `\Unnnnnnnn` ) notations.
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-10 01:37:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								Conversely, escape characters are not parsed in string literals designated by backticks. It is important to note that, unlike Go, Prometheus does not discard newlines inside backticks.
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Example:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    "this is a string"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    'these are unescaped: \n \\ \t'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    `these are not unescaped: \n ' " \t` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-06 02:31:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								### Float literals and time durations
  
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-06 02:31:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								Scalar float values can be written as literal integer or floating-point numbers
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								in the format (whitespace only included for better readability):
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-25 19:34:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    [-+]?(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								          [0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        | 0[xX][0-9a-fA-F]+
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        | [nN][aA][nN]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        | [iI][nN][fF]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Examples:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    23
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    -2.43
							 
						 
					
						
							
								
									
										
										
										
											2020-07-25 19:34:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    3.4e-9
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    0x8f
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    -Inf
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    NaN
							 
						 
					
						
							
								
									
										
										
										
											2024-04-19 21:22:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-06 02:31:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								Additionally, underscores (`_`) can be used in between decimal or hexadecimal
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								digits to improve readability.
							 
						 
					
						
							
								
									
										
										
										
											2024-04-19 21:22:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Examples:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-06 02:31:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    1_000_000
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    .123_456_789
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    0x_53_AB_F3_82
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Float literals are also used to specify durations in seconds. For convenience,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								decimal integer numbers may be combined with the following
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								time units:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								*  `ms`  –  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								*  `s`  – –  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								*  `m`  – –  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								*  `h`  – –  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								*  `d`  – –  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								*  `w`  – –  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
										 
							
							
								*  `y`  – –  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Suffixing a decimal integer number with one of the units above is a different
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								representation of the equivalent number of seconds as a bare float literal.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Examples:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    1s # Equivalent to 1.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    2m # Equivalent to 120.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    1ms # Equivalent to 0.001.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    -2h # Equivalent to -7200.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								The following examples do _not_  work:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    0xABm # No suffixing of hexadecimal numbers.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    1.5h # Time units cannot be combined with a floating point.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    +Infd # No suffixing of ±Inf or NaN.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Multiple units can be combined by concatenation of suffixed integers. Units
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								must be ordered from the longest to the shortest. A given unit must only appear
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								once per float literal.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Examples:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    1h30m # Equivalent to 5400s and thus 5400.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    12h34m56s # Equivalent to 45296s and thus 45296.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    54s321ms # Equivalent to 54.321.
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-10 01:37:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								## Time series selectors
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-07-22 23:17:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								These are the basic building-blocks that instruct PromQL what data to fetch.
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								### Instant vector selectors
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Instant vector selectors allow the selection of a set of time series and a
							 
						 
					
						
							
								
									
										
										
										
											2024-02-10 01:37:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								single sample value for each at a given timestamp (point in time).  In the simplest
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								form, only a metric name is specified, which results in an instant vector
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								containing elements for all time series that have this metric name.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-10-18 09:11:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								The value returned will be that of the most recent sample at or before the
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								query's evaluation timestamp (in the case of an
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								[instant query ](api.md#instant-queries ))
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								or the current step within the query (in the case of a
							 
						 
					
						
							
								
									
										
										
										
											2024-11-24 19:37:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								[range query ](api.md#range-queries )).
							 
						 
					
						
							
								
									
										
										
										
											2023-10-18 09:11:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								The [`@` modifier ](#modifier ) allows overriding the timestamp relative to which
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								the selection takes place. Time series are only returned if their most recent sample is less than the [lookback period ](#staleness ) ago.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								This example selects all time series that have the `http_requests_total`  metric
							 
						 
					
						
							
								
									
										
										
										
											2023-10-18 09:11:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								name, returning the most recent sample for each:
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    http_requests_total
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-10 01:37:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								It is possible to filter these time series further by appending a comma-separated list of label
							 
						 
					
						
							
								
									
										
										
										
											2019-12-20 19:28:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								matchers in curly braces (`{}`).
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								This example selects only those time series with the `http_requests_total` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								metric name that also have the `job`  label set to `prometheus`  and their
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								`group`  label set to `canary` : 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    http_requests_total{job="prometheus",group="canary"}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								It is also possible to negatively match a label value, or to match label values
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								against regular expressions. The following label matching operators exist:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								*  `=` : Select labels that are exactly equal to the provided string. 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								*  `!=` : Select labels that are not equal to the provided string. 
						 
					
						
							
								
									
										
										
										
											2019-05-09 18:12:32 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								*  `=~` : Select labels that regex-match the provided string. 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								*  `!~` : Select labels that do not regex-match the provided string. 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-11-25 05:03:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								[Regex ](#regular-expressions ) matches are fully anchored. A match of `env=~"foo"`  is treated as `env=~"^foo$"` .
							 
						 
					
						
							
								
									
										
										
										
											2022-01-10 23:44:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								For example, this selects all `http_requests_total`  time series for `staging` ,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								`testing` , and `development`  environments and HTTP methods other than `GET` . 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    http_requests_total{environment=~"staging|testing|development",method!="GET"}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-08-13 18:38:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								Label matchers that match empty label values also select all time series that
							 
						 
					
						
							
								
									
										
										
										
											2022-01-10 23:44:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								do not have the specific label set at all. It is possible to have multiple matchers for the same label name.
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-10 01:37:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								For example, given the dataset:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    http_requests_total
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    http_requests_total{replica="rep-a"}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    http_requests_total{replica="rep-b"}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    http_requests_total{environment="development"}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								The query `http_requests_total{environment=""}`  would match and return:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    http_requests_total
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    http_requests_total{replica="rep-a"}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    http_requests_total{replica="rep-b"}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								and would exclude:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    http_requests_total{environment="development"}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-05-29 03:37:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								Multiple matchers can be used for the same label name; they all must pass for a result to be returned.
							 
						 
					
						
							
								
									
										
										
										
											2024-02-10 01:37:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								The query:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    http_requests_total{replica!="rep-a",replica=~"rep.*"}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Would then match:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    http_requests_total{replica="rep-b"}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Vector selectors must either specify a name or at least one label matcher
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								that does not match the empty string. The following expression is illegal:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    {job=~".*"} # Bad!
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								In contrast, these expressions are valid as they both have a selector that does not
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								match empty label values.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    {job=~".+"}              # Good!
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    {job=~".*",method="get"} # Good!
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Label matchers can also be applied to metric names by matching against the internal
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								`__name__`  label. For example, the expression `http_requests_total`  is equivalent to 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								`{__name__="http_requests_total"}` . Matchers other than `=`  (`!=`, `=~` , `!~` ) may also be used. 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								The following expression selects all metrics that have a name starting with `job:` :
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-22 20:11:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    {__name__=~"job:.*"}
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-03-05 21:20:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								The metric name must not be one of the keywords `bool` , `on` , `ignoring` , `group_left`  and `group_right` . The following expression is illegal:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    on{} # Bad!
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								A workaround for this restriction is to use the `__name__`  label:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    {__name__="on"} # Good!
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								### Range Vector Selectors
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Range vector literals work like instant vector literals, except that they
							 
						 
					
						
							
								
									
										
										
										
											2024-10-06 02:31:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								select a range of samples back from the current instant. Syntactically, a
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								[float literal ](#float-literals-and-time-durations ) is appended in square
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								brackets (`[]`) at the end of a vector selector to specify for how many seconds
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								back in time values should be fetched for each resulting range vector element.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Commonly, the float literal uses the syntax with one or more time units, e.g.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								`[5m]` . The range is a left-open and right-closed interval, i.e. samples with 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								timestamps coinciding with the left boundary of the range are excluded from the
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								selection, while samples coinciding with the right boundary of the range are
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								included in the selection.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								In this example, we select all the values recorded less than 5m ago for all
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								time series that have the metric name `http_requests_total`  and a `job`  label
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								set to `prometheus` :
							 
						 
					
						
							
								
									
										
										
										
											2020-08-05 03:12:41 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    http_requests_total{job="prometheus"}[5m]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								### Offset modifier
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								The `offset`  modifier allows changing the time offset for individual
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								instant and range vectors in a query.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								For example, the following expression returns the value of
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								`http_requests_total`  5 minutes in the past relative to the current 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								query evaluation time:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    http_requests_total offset 5m
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Note that the `offset`  modifier always needs to follow the selector
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								immediately, i.e. the following would be correct:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    sum(http_requests_total{method="GET"} offset 5m) // GOOD.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								While the following would be *incorrect* :
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    sum(http_requests_total{method="GET"}) offset 5m // INVALID.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-16 19:09:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								The same works for range vectors. This returns the 5-minute [rate ](./functions.md#rate )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								that `http_requests_total`  had a week ago:
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    rate(http_requests_total[5m] offset 1w)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-10 01:37:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								When querying for samples in the past, a negative offset will enable temporal comparisons forward in time:
							 
						 
					
						
							
								
									
										
										
										
											2021-02-15 10:25:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    rate(http_requests_total[5m] offset -1w)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-12 00:01:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								Note that this allows a query to look ahead of its evaluation time.
							 
						 
					
						
							
								
									
										
										
										
											2021-02-22 02:03:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-01-20 18:57:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								### @ modifier
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								The `@`  modifier allows changing the evaluation time for individual instant
							 
						 
					
						
							
								
									
										
										
										
											2021-02-10 00:03:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								and range vectors in a query. The time supplied to the `@`  modifier
							 
						 
					
						
							
								
									
										
										
										
											2025-09-02 19:44:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								is a Unix timestamp and described with a float literal.
							 
						 
					
						
							
								
									
										
										
										
											2021-01-20 18:57:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								For example, the following expression returns the value of
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								`http_requests_total`  at `2021-01-04T07:40:00+00:00` : 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    http_requests_total @ 1609746000
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Note that the `@`  modifier always needs to follow the selector
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								immediately, i.e. the following would be correct:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    sum(http_requests_total{method="GET"} @ 1609746000) // GOOD.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								While the following would be *incorrect* :
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    sum(http_requests_total{method="GET"}) @ 1609746000 // INVALID.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								The same works for range vectors. This returns the 5-minute rate that
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								`http_requests_total`  had at `2021-01-04T07:40:00+00:00` : 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    rate(http_requests_total[5m] @ 1609746000)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-10 01:37:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								The `@`  modifier supports all representations of numeric literals described above.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								It works with the `offset`  modifier where the offset is applied relative to the `@` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								modifier time.  The results are the same irrespective of the order of the modifiers.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								For example, these two queries will produce the same result:
							 
						 
					
						
							
								
									
										
										
										
											2021-01-20 18:57:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    # offset after @
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    http_requests_total @ 1609746000 offset 5m
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    # offset before @
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    http_requests_total offset 5m @ 1609746000
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-10 00:03:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								Additionally, `start()`  and `end()`  can also be used as values for the `@`  modifier as special values.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								For a range query, they resolve to the start and end of the range query respectively and remain the same for all steps.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								For an instant query, `start()`  and `end()`  both resolve to the evaluation time.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    http_requests_total @ start()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    rate(http_requests_total[5m] @ end())
							 
						 
					
						
							
								
									
										
										
										
											2021-01-20 18:57:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-12 00:01:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								Note that the `@`  modifier allows a query to look ahead of its evaluation time.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-12-22 21:47:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								## Subquery
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-25 19:34:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								Subquery allows you to run an instant query for a given range and resolution. The result of a subquery is a range vector.
							 
						 
					
						
							
								
									
										
										
										
											2018-12-22 21:47:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-06 02:31:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								Syntax: `<instant_query> '[' <range> ':' [<resolution>] ']' [ @ <float_literal> ] [ offset <float_literal> ]` 
							 
						 
					
						
							
								
									
										
										
										
											2018-12-22 21:47:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								*  `<resolution>`  is optional. Default is the global evaluation interval. 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								## Operators
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Prometheus supports many binary and aggregation operators. These are described
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								in detail in the [expression language operators ](operators.md ) page.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								## Functions
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Prometheus supports several functions to operate on data. These are described
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								in detail in the [expression language functions ](functions.md ) page.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-25 18:01:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								## Comments
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								PromQL supports line comments that start with `#` . Example:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        # This is a comment
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-11-25 05:03:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								## Regular expressions
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								All regular expressions in Prometheus use [RE2 syntax ](https://github.com/google/re2/wiki/Syntax ).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Regex matches are always fully anchored.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								## Gotchas
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-01 20:40:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								### Staleness
  
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-10 01:37:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								The timestamps at which to sample data, during a query, are selected
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								independently of the actual present time series data. This is mainly to support
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								cases like aggregation (`sum`, `avg` , and so on), where multiple aggregated
							 
						 
					
						
							
								
									
										
										
										
											2024-02-10 01:37:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								time series do not precisely align in time. Because of their independence,
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Prometheus needs to assign a value at those timestamps for each relevant time
							 
						 
					
						
							
								
									
										
										
										
											2024-04-09 00:46:52 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								series. It does so by taking the newest sample that is less than the lookback period ago.
							 
						 
					
						
							
								
									
										
										
										
											2023-10-18 09:11:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								The lookback period is 5 minutes by default, but can be
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								[set with the `--query.lookback-delta` flag ](../command-line/prometheus.md )
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-01 20:40:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								If a target scrape or rule evaluation no longer returns a sample for a time
							 
						 
					
						
							
								
									
										
										
										
											2024-02-10 01:37:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								series that was previously present, this time series will be marked as stale.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								If a target is removed, the previously retrieved time series will be marked as
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								stale soon after removal.
							 
						 
					
						
							
								
									
										
										
										
											2017-11-01 20:40:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								If a query is evaluated at a sampling timestamp after a time series is marked
							 
						 
					
						
							
								
									
										
										
										
											2024-02-10 01:37:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								as stale, then no value is returned for that time series. If new samples are
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								subsequently ingested for that time series, they will be returned as expected.
							 
						 
					
						
							
								
									
										
										
										
											2017-11-01 20:40:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-10 01:37:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								A time series will go stale when it is no longer exported, or the target no
							 
						 
					
						
							
								
									
										
										
										
											2025-05-29 03:37:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								longer exists. Such time series will disappear from graphs
							 
						 
					
						
							
								
									
										
										
										
											2024-02-10 01:37:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								at the times of their latest collected sample, and they will not be returned
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								in queries after they are marked stale.
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-05-29 03:37:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								Some exporters, which put their own timestamps on samples, get a different behaviour:
							 
						 
					
						
							
								
									
										
										
										
											2024-02-10 01:37:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								series that stop being exported take the last value for (by default) 5 minutes before
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								disappearing. The `track_timestamps_staleness`  setting can change this.
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								### Avoiding slow queries and overloads
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-10 01:37:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								If a query needs to operate on a substantial amount of data, graphing it might
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								time out or overload the server or browser. Thus, when constructing queries
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								over unknown data, always start building the query in the tabular view of
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Prometheus's expression browser until the result set seems reasonable
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								(hundreds, not thousands, of time series at most).  Only when you have filtered
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								or aggregated your data sufficiently, switch to graph mode. If the expression
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								still takes too long to graph ad-hoc, pre-record it via a [recording
							 
						 
					
						
							
								
									
										
										
										
											2017-10-27 15:47:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								rule](../configuration/recording_rules.md#recording-rules).
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								This is especially relevant for Prometheus's query language, where a bare
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								metric name selector like `api_http_requests_total`  could expand to thousands
							 
						 
					
						
							
								
									
										
										
										
											2024-02-10 01:37:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								of time series with different labels. Also, keep in mind that expressions that
							 
						 
					
						
							
								
									
										
										
										
											2017-10-26 21:53:27 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								aggregate over many time series will generate load on the server even if the
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								output is only a small number of time series. This is similar to how it would
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								be slow to sum all values of a column in a relational database, even if the
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								output value is only a single number.