Saturday, March 4, 2023

PromQL (Prometheus Query Language) notes

PromQL (Prometheus Query Language) is a query language used to retrieve and manipulate time series data stored in Prometheus. Mos important aspects of PromQL:

  • Selecting metrics: You can select metrics by their name or by using regular expressions. For example, up selects all metrics with the name up, while node_cpu.* selects all metrics with names starting with node_cpu.
  • Filtering metrics: You can filter metrics by their labels using curly braces {}. For example, up{job="prometheus"} selects all metrics with the name up and the label job equal to prometheus.
  • Aggregating data: PromQL provides a variety of functions to aggregate time series data. For example, sum() calculates the sum of values across multiple time series, while avg() calculates the average value across multiple time series.
  • Grouping data: You can group data by one or more labels using the by keyword. For example, sum(rate(http_requests_total{method="GET"}[5m])) by (status_code) groups the data by the status_code label.
  • Working with time: PromQL supports a variety of time-related functions, such as time() to get the current timestamp, offset() to shift the data by a certain time interval, and rate() to calculate the rate of change over a time period.

PromQL provides a powerful and flexible way to analyze and query time series data stored in Prometheus.

No comments:

Post a Comment