Prometheus Selectors
Prometheus, an open-source monitoring and alerting toolkit, provides various time series selectors for querying and retrieving metrics data. Here are some of the commonly used time series selectors in Prometheus:
1. Metric name selector: You can select time series data based on the metric name. For example, "up" selects all time series with the metric name "up".
2. Label matching selector: Prometheus uses labels to identify and filter time series data. You can use label matching selectors to specify conditions for label values. The commonly used label matching operators are "=", "!=", "=~" (regex match), and "!~" (regex non-match). For example, job="node" selects all time series with the label "job" having the value "node".
3. Regular expression selector: You can use regular expressions to match metric names or label values. For example, {__name__=~"http_.*_requests_total"} selects all time series with metric names starting with "http_" and ending with "_requests_total".
4. Aggregation selector: Prometheus allows aggregation of time series using functions such as sum, avg, min, max, etc. Aggregation selectors enable you to perform calculations on multiple time series and retrieve a single result. For example, sum(http_requests_total) calculates the sum of all time series with the metric name http_requests_total.
5. Offset modifier: You can apply the offset modifier to a selector to shift the time range for retrieving time series data. It allows you to select time series data from a specific time window relative to the current evaluation time. For example, "http_requests_total offset 5m" selects all time series with the metric name http_requests_total from the past 5 minutes.
6. Range vector selector: Prometheus supports range vectors, which allow you to select a range of time series data over a specified time interval. Range vector selectors are used in combination with functions like rate, increase, delta, etc., to calculate rates or changes over time. For example, "rate(http_requests_total[5m])" calculates the per-second rate of increase of the http_requests_total metric over the past 5 minutes.
These are some of the common time series selectors in Prometheus. They provide flexibility in querying and analyzing metrics data to gain insights and create alerts based on specific criteria.