PromQL

Getting started

Create your first chart using a PromQL query. Start by creating a dashboard in MetricsCreate dashboard.

Create a new chart on your dashboard, select PromQL as the query type, and use a query like the one below:

Average rate of http requests
avg(rate(http_requests_total))

Want to query logs instead of metrics?

PromQL can only query metrics. To query logs, use SQL queries instead.

PromQL is designed for querying time series data. Use your existing PromQL knowledge to query the metrics you send to Better Stack.

Supported operations

Better Stack supports the following PromQL operations:

  • Metric selection with label matching, for example http_requests_total{method="GET"}
  • Aggregation operators with by and without clauses
  • Mathematical operations between series with the same tags

Aggregation operators include:

  • sum: Calculate the sum of elements in the vector
  • avg: Calculate the average of elements in the vector
  • min: Select the minimum element of the vector
  • max: Select the maximum element of the vector
  • count: Count the number of elements in the vector
  • topk: Select the k largest elements of the vector
  • bottomk: Select the k smallest elements of the vector
  • stddev and stdvar: Calculate the standard deviation or variance of the vector

Supported functions

  • Rates and changes: rate, irate, increase, and delta.
  • Over-time aggregations: avg_over_time, sum_over_time, min_over_time, max_over_time, and count_over_time.
  • Histograms: histogram_quantile and histogram_fraction.
  • Missing data: absent and absent_over_time.
  • Value adjustments: round, clamp, clamp_min, clamp_max, and timestamp.
  • Math: abs, ceil, floor, exp, ln, log2, log10, sqrt, and sgn.
  • Date and time: hour, minute, day_of_week, day_of_month, day_of_year, days_in_month, month, and year.

Examples

See the examples below for full queries using PromQL in Better Stack.

HTTP request rate by method

Query the rate of HTTP requests
sum by (method) (rate(http_requests_total))

This query returns the rate of HTTP requests, grouped by HTTP method.

CPU usage rate by pod

Query CPU usage
rate(container_cpu_usage_seconds_total{container!=""}) without (id)

This query returns the per-second rate of CPU usage over the last 15 minutes for each pod, excluding the "id" label.

Average memory usage rate

Query memory usage by instance
avg by (instance) (rate(process_resident_memory_bytes))

This query calculates the average per-second rate of memory usage for each instance.

Top 5 most frequently accessed API endpoints

Query the top 5 most used api endpoints
topk(5, sum by (endpoint) (rate(api_requests_total)))

This query returns the top 5 API endpoints with the highest per-second request rate.

Network I/O rate by interface

Query the network transmission of each interface
sum by (interface) (rate(network_transmit_bytes_total))

This query returns the per-second rate of network transmission (in bytes), grouped by network interface.

Need help?

Please let us know at hello@betterstack.com.
We're happy to help! 🙏