promQL
2021-04-24 本文已影响0人
慕知
一,简单运算
1,查看三台机器的总内存
三台机器为master,和2台node节点,总内存为3G
2,查看可用内存
image.png[root@\ k8s-n-01~]# free -m
total used free shared buff/cache available
Mem: 2968 1183 335 10 1449 1780
[root@\ k8s-n-02~]# free -m
total used free shared buff/cache available
Mem: 2968 1011 1101 9 855 1917
[root@\ k8s-m-01~/yaml]# free -m
total used free shared buff/cache available
Mem: 2968 1566 142 9 1258 1550
Swap: 0 0 0
计算机内存空闲率
计算机内存空闲率
# 更改scheduler监听的端口(不然监控不到)
[root@\ k8s-m-01~]# cd /etc/kubernetes/manifests/
[root@\ k8s-m-01/etc/kubernetes/manifests]# ll
total 16
-rw-------. 1 root root 2216 Mar 25 19:55 etcd.yaml
-rw-------. 1 root root 3330 Mar 25 19:55 kube-apiserver.yaml
-rw-------. 1 root root 2827 Mar 25 19:55 kube-controller-manager.yaml
-rw-------. 1 root root 1411 Apr 23 21:47 kube-scheduler.yaml
[root@\ k8s-m-01/etc/kubernetes/manifests]# vim kube-scheduler.yaml
- --bind-address=127.0.0.1
更改为
- --bind-address=0.0.0.0
# 重新部署
[root@\ k8s-m-01/etc/kubernetes/manifests]# kubectl apply -f kube-scheduler.yaml
pod/kube-scheduler created
# 查看pod是否启动
[root@\ k8s-m-01/etc/kubernetes/manifests]# kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
coredns-f68b4c98f-dr9hj 1/1 Running 1 29d
coredns-f68b4c98f-l5mhh 1/1 Running 1 29d
etcd-k8s-m-01 1/1 Running 1 29d
kube-apiserver-k8s-m-01 1/1 Running 1 29d
kube-controller-manager-k8s-m-01 1/1 Running 1 29d
kube-flannel-ds-bjhc8 1/1 Running 1 29d
kube-flannel-ds-lbzpv 1/1 Running 1 29d
kube-flannel-ds-mxvqx 1/1 Running 1 29d
kube-proxy-cl5fk 1/1 Running 1 29d
kube-proxy-dkw52 1/1 Running 1 29d
kube-proxy-h499h 1/1 Running 1 29d
kube-scheduler 0/1 CrashLoopBackOff 2 32s
kube-scheduler-k8s-m-01 1/1 Running 0 111s
3,查询5分钟以内的数据
查询5分钟以内的数据+ - * / % ^
=:选择正好相等的字符串标签
!=:选择不相等的字符串标签
=~:选择匹配正则表达式的标签(或⼦标签)
!=:选择不匹配正则表达式的标签(或⼦标签)
s:seconds
m:minutes
h:hours
d:days
w:weeks
y:years
4,查询30分钟以前到35分钟之内的数据
image.png 查看1小时之内的node1内存数据5, 判断条件=
![image.png](https://img.haomeiwen.com/i23958203/7d18c05f7ce9c9fb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)6, 判断条件不等于!=
image.png7,正则匹配
image.png8,正则匹配,取反
image.png9,运算 加减乘除
原来的值 加发运算 乘法运算 除法 平方9,大小取值
大小取值二,集合运算
1,and
and2,or
or3,unless
排除三,聚合运算
1,sum 求和函数
sum,和2,min 求最小值
求最小值3,max 求最大值
求最大值4,平均数
image.png5,count
统计总个数6, 获取最小的2个值
image.png7, 获取最大的2个值
image.pnghttps://prometheus.io/docs/prometheus/latest/querying/functions/函数