@ -14,7 +14,7 @@ systems via the [HTTP API](api.md).
## Examples
## Examples
This document is meant as a reference. For learning, it might be easier to
This document is a Prometheus basic language reference. For learning, it may be easier to
start with a couple of [examples](examples.md).
start with a couple of [examples](examples.md).
## Expression language data types
## Expression language data types
@ -28,9 +28,9 @@ evaluate to one of four types:
* **String** - a simple string value; currently unused
* **String** - a simple string value; currently unused
Depending on the use-case (e.g. when graphing vs. displaying the output of an
Depending on the use-case (e.g. when graphing vs. displaying the output of an
expression), only some of these types are legal as the result from a
expression), only some of these types are legal as the result of a
user-specified expression. For example, an expression that returns an instant
user-specified expression. For example, an expression that returns an instant
vector is the only type that can be directly graphed.
vector is the only type which can be graphed.
_Notes about the experimental native histograms:_
_Notes about the experimental native histograms:_
@ -46,16 +46,15 @@ _Notes about the experimental native histograms:_
### String literals
### String literals
Strings may be specified as literals in single quotes, double quotes or
String literals are designated by single quotes, double quotes or backticks.
backticks.
PromQL follows the same [escaping rules as
PromQL follows the same [escaping rules as
Go](https://golang.org/ref/spec#String_literals). In single or double quotes a
Go](https://golang.org/ref/spec#String_literals). For string literals in single or double quotes, a
backslash begins an escape sequence, which may be followed by `a`, `b`, `f`,
backslash begins an escape sequence, which may be followed by `a`, `b`, `f`,
`n`, `r`, `t`, `v` or `\`. Specific characters can be provided using octal
`n`, `r`, `t`, `v` or `\`. Specific characters can be provided using octal
(`\nnn`) or hexadecimal (`\xnn`, `\unnnn` and `\Unnnnnnnn`).
(`\nnn`) or hexadecimal (`\xnn`, `\unnnn` and `\Unnnnnnnn`) notations.
No escaping is processed inside backticks. Unlike Go, Prometheus does not discard newlines inside backticks.
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.
Example:
Example:
@ -83,13 +82,17 @@ Examples:
-Inf
-Inf
NaN
NaN
## Time series Selectors
## Time series selectors
Time series selectors are responsible for selecting the times series and raw or inferred sample timestamps and values.
Time series *selectors* are not to be confused with higher level concept of instant and range *queries* that can execute the time series *selectors*. A higher level instant query would evaluate the given selector at one point in time, however the range query would evaluate the selector at multiple different times in between a minimum and maximum timestamp at regular steps.
### Instant vector selectors
### Instant vector selectors
Instant vector selectors allow the selection of a set of time series and a
Instant vector selectors allow the selection of a set of time series and a
single sample value for each at a given timestamp (instant): in the simplest
single sample value for each at a given timestamp (point in time). In the simplest
form, only a metric name is specified. This results in an instant vector
form, only a metric name is specified, which results in an instant vector
containing elements for all time series that have this metric name.
containing elements for all time series that have this metric name.
This example selects all time series that have the `http_requests_total` metric
This example selects all time series that have the `http_requests_total` metric
@ -97,7 +100,7 @@ name:
http_requests_total
http_requests_total
It is possible to filter these time series further by appending a commaseparated list of label
It is possible to filter these time series further by appending a comma-separated list of label
matchers in curly braces (`{}`).
matchers in curly braces (`{}`).
This example selects only those time series with the `http_requests_total`
This example selects only those time series with the `http_requests_total`
@ -124,6 +127,33 @@ For example, this selects all `http_requests_total` time series for `staging`,
Label matchers that match empty label values also select all time series that
Label matchers that match empty label values also select all time series that
do not have the specific label set at all. It is possible to have multiple matchers for the same label name.
do not have the specific label set at all. It is possible to have multiple matchers for the same label name.
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"}
Multiple matchers can be used for the same label name; they all must pass for a result to be returned.