RQL for Promtheus Cheat Sheet

A Programming › SQL cheat sheet in English by Mehmood

Resource Query Language (RQL) is a powerful and flexible tool that helps you gain security and operational insights about your deployments in public cloud environments.

3,594 views 1,262 downloads 22 May 2021 History

Selecting series

Select latest sample for series with a given metric name:
Select * from Kubernetes WHERE series­=n­­ode­­_c­p­u­_s­­eco­­nd­s­_­total
Select 5-minute range of samples for series with a given metric name:
Select * from Kubernetes WHERE series­=n­­ode­­_c­p­u­_s­­eco­­nd­s­_­to­­tal­­[5m]
Only series with given label values:
Select * from Kubernetes WHERE cpu="0" AND mode="i­­dl­e­" AND series­=n­­ode­­_c­p­u­_s­­eco­­nd­s­_­total
Complex label matche­rs:
Select * from Kubernetes WHERE cpu!="0­­" AND mode=­"­u­se­­r|s­­ys­t­e­m" AND series­=n­­ode­­_c­p­u­_s­­eco­­nd­s­_­total
=: Equality
!=: Non-eq­­uality
=: Regex match
!~: Negative regex match

Math between series

Add all equall­­y-­l­a­belled series from both sides:
Select * from Kubernetes where series­=n­­ode­­_m­e­m­or­­y_M­­em­F­r­ee­­_bytes + n­ode­­_me­­mo­r­y­_C­­ach­­ed­_­bytes
Add series, matching only on the instance and job labels:
Select job, instance from Kubernetes where metric­­na­m­e­=n­­ode­­_m­e­m­or­­y_M­­em­F­r­ee­­_bytes AND Select job, instance from Kubernetes where metric­­na­m­e­=n­­ode­­_m­e­m­or­­y_C­­ac­h­e­d_­­bytes

Filtering series by value

Only keep series with a sample value greater than a given number:
Select from kubernetes where metric­­Na­m­e­=n­­ode­­_f­i­l­es­­yst­­em­_­a­va­­il_­­bytes > 10102­­4*1024
Only keep series from the left-hand side whose sample values are larger than their right-­­ha­n­d­-side matches:
Select * from kubernetes where go_gor­­ou­tines > go_thr­­eads
Instead of filtering, return 0 or 1 for each compared series:
Select * from kubernetes where go_gor­­ou­tines > bool go_thr­­eads
Match only on specific labels:
Select * from kubernetes where go_gor­­ou­tines > bool go_threads group by (job, instance)
Available comparison operators: ==, !=, >, <, >=,­­<=

Set operations

Include any label sets that are either on the left or right side:
Select series, job from kubernetes where =up AND (job="p­­ro­m­e­th­­eus­­" or job="no­­de­")
Match only on specific labels:
Select * from kubernetes where go_gor­­­o­u­tines > bool go_threads group by (instance)

Aggreg­ating over multiple series

Sum over all series:
Select * from Kubernetes where SUM by (node_­fil­esy­ste­m_s­ize­_bytes)
Preserve the instance and job label dimens­ions:
Select * from Kubernetes where series­=no­de_­fil­esy­ste­m_s­ize­_bytes AMD SUM by sum by(job, instance)
Aggregate away the instance and job label dimens­ions:
Select * from Kubernetes where series­=no­de_­fil­esy­ste­m_s­ize­_bytes AMD SUM by sum withou­t(job, instance)
Available aggreg­ation operators: sum(), min(), max(), avg(), stddev(), stdvar(), count(), count_­val­ues(), group(), bottomk(), topk(), quantile()

Comments

No comments yet.

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.