一、概述
QL顾名思义,Query language即查询语言。Prometheus作为强大的开源监控系统,最大的依赖便是PromQL。是监控数据个性化查询、展示的基础。所以要掌握Prometheus,掌握PromQL是必备的前提。
瞬时向量:包含该时间序列中最新的⼀个样本值
区间向量:⼀段时间范围内的数据
二、Promethus容器化
普罗米修斯容器化就是在kubernetes中安装。
三、下载普罗米修斯配置清单
[root@kubernetes-master-01 ~]# git clone -b release-0.5 --single-branch https://github.com/prometheus-operator/kube-prometheus.git
[root@kubernetes-master-01 ~]# cd kube-prometheus/
[root@kubernetes-master-01 setup]# pwd
/root/kube-prometheus/manifests/setup
[root@kubernetes-master-01 setup]# kubectl apply -f ./
# 查看一下
[root@kubernetes-master-01 setup]# kubectl get pods -n monitoring
NAME READY STATUS RESTARTS AGE
prometheus-operator-848d669f6d-qcxhc 2/2 Running 0 45s
# 部署普罗米修斯
[root@kubernetes-master-01 setup]# cd ..
[root@kubernetes-master-01 manifests]# pwd
/root/kube-prometheus/manifests
[root@kubernetes-master-01 manifests]# kubectl apply -f ./
四、PromQL简单运算
1.简单运算
#1.查询5分钟以内的数据
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174412632-682655739.png)
#2.查询30分钟以前的数据
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174423768-501151877.png)
#3.等于查询
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174434888-180621750.png)
#4.不等于查询
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174443690-1807887798.png)
#5.正则匹配
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174452630-444675244.png)
#6.正则取反
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174459612-1362510459.png)
#7.计算服务器内存空闲率
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174508010-990773711.png)
#8.计算空闲内存小于1G
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174516038-2115780520.png)
#9.计算空闲内存等于一个数字
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174524155-110894298.png)
2.聚合运算
逻辑运算
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174532130-281023042.png)
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174537693-1676307735.png)
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174545639-1416154237.png)
聚合函数
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174556900-2029350063.png)
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174605116-933309583.png)
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174610309-99148453.png)
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174641741-328031217.png)
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174648527-1828617820.png)
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174654446-1691500329.png)
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174702171-1631581851.png)
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174708613-266099194.png)
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174717087-1724947538.png)
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174724411-866905616.png)
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174731181-1869446602.png)
3.二进制运算符优先级
^
*,/,%
+, -
==,!=,<=,<,>=,>
and, unless
or
4.特殊查询
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174739010-1443359321.png)
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174745451-1179043997.png)
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174754123-1721392233.png)
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174800779-559414812.png)
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174809099-690038503.png)
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174815196-989741808.png)
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174821693-356732853.png)
- 基于范围向量预测从现在开始到某个时间的资源消耗情况
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174830945-500919031.png)
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174837588-176958581.png)
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174850891-1211762425.png)
五、Grafana添加数据源
![](https://img2020.cnblogs.com/blog/2087967/202105/2087967-20210521174908103-1022781298.png)