From the course: Prometheus Essential Training
Introduction to querying with PromQL - Prometheus Tutorial
From the course: Prometheus Essential Training
Introduction to querying with PromQL
- [Instructor] Welcome. In this video, we will discuss the basics of writing queries in Prometheus using PromQL. PromQL stands for Prometheus Query Language, and it helps you select and aggregate Prometheus time series data in real-time. The queries you write can be consumed in different ways. You can use graphs, which is the most popular approach. You can also use the HTTP API, and so on. PromQL can also produce nested expressions. Each subquery produces a result that can be used by the larger expressions. Also, because it's a domain-specific language written in Golang, you can find a lot of similarities with the Golang language. Let's explore a couple of basic concepts needed for writing queries. The result of a query is a set of time series, and any set of related time series is called a vector. In Prometheus, the evaluation of a query can produce three main data types. The first is an instant vector. An instant vector is a vector that has a single sample for each time series, all at the same timestamp. The timestamp can be the current evaluation timestamp, or one specified using a query modifier. Instant vectors can be graphed, because they have a corresponding value on the Y axis, which is a time series value. And one for the X axis, which is a time series timestamp. Range vectors are vectors that have a range of values over a given time duration for each time series. Range vectors cannot be graphed, because they have multiple Y axis values for each timestamp. Finally, a scaler. A scaler is simply a single numeric floating point value. Next, we have literals. Literals are constants values that can be used in queries. There are two types of literals. The first is string literals, which are represented by single or double quotes, or back ticks. The other is a float literal, which is represented by single point numbers or decimals. Selectors are integral parts of every query. You can use them to select a time series, which produces a vector. The first type of selector is called an instant vector selector. This allows the selection of a time series, and a set of values at each given timestamp. You can also negatively match a value and match by rejects. To select HTTP requests that are not in the canary group, we can add a negative selector. And to match a couple of groups, using the Regex or operators, we can add a Regex selector. We can also match a metric name using the internal name label. This is useful if the metric name violates query rules. Next, we have range vector selectors. These allow the selection of a time series that includes a range of values per timestamp for a given duration. The range selector simply appends a duration to the query, and transforms an instant vector into a range vector. The time durations are specified as numbers, followed by the units shown on the screen. Next, we have the offset modifier. This is used to change the time offset for an instant or range vector. The specified offset shifts the time range for the query backward. For example, the offset shown will return values five minutes ago relative to the current evaluation time. Finally, the ask modifier is used to change the evaluation time of a query. The time specified is a unique timestamp, and is represented as a float literal. This works for both instant and range vectors.