转自:https://yunlzheng.gitbook.io/prometheus-book/parti-prometheus-ji-chu/promql/prometheus-query-language
//非常全面易懂的教程
1.语法
当我们直接使用监控指标名称查询时,可以查询该指标下的所有时间序列,只会返回瞬时向量表达式,返回值中只会包含该时间序列中的最新的一个样本值:
http_requests_total{code="200",handler="alerts",instance="localhost:9090",job="prometheus",method="get"}=([email protected]) http_requests_total{code="200",handler="graph",instance="localhost:9090",job="prometheus",method="get"}=([email protected]) http_requests_total //直接使用监控指标名称查询时,可以查询该指标下的所有时间序列。如上。 http_requests_total{}
1.1 筛选
PromQL支持使用=
和!=
两种完全匹配模式:
- 通过使用
label=value
可以选择那些标签满足表达式定义的时间序列; - 反之使用
label!=value
则可以根据标签匹配排除时间序列;
需要查询所有http_requests_total时间序列中满足或不满足标签instance为localhost:9090的时间序列:
http_requests_total{instance="localhost:9090"} http_requests_total{instance!="localhost:9090"}除了使用完全匹配的方式对时间序列进行过滤以外,PromQL还可以支持使用正则表达式作为匹配条件,多个表达式之间使用
|
进行分离:
- 使用
label=~regx
表示选择那些标签符合正则表达式定义的时间序列; - 反之使用
label!~regx
进行排除; (这里~号是什么意思?可以理解为表示正则的符号?)
http_requests_total{environment=~"staging|testing|development",method!="GET"}
1.3 范围查询
http_request_total{} # 瞬时向量表达式,选择当前最新的数据 http_requests_total{}[5m] //选择最近5分钟内的所有样本数据 //时间位移操作 http_request_total{} offset 5m //5分钟前的瞬时样本数据 http_request_total{}[1d] offset 1d //昨天一天的区间内的样本数据
标签:http,9090,PQL,学习,序列,requests,total,localhost From: https://www.cnblogs.com/BlueBlueSea/p/17133039.html