目前prometheus 给pod的内存告警阀值设置的85%,由于JVM 设置最高申请内存为pod limit 的75%,通过arthas-boot查看到堆内存和元空间占用内存之和跟prometheus告警值不同。
使用container_memory_rss值进行告警
- alert: Pod内存使用率
expr: |
sum(container_memory_rss{image!=""}) by(pod, namespace) /
sum(container_spec_memory_limit_bytes{image!=""}) by(pod, namespace) * 100 != +inf > 85
for: 5m
labels:
severity: warning
annotations:
summary: "命名空间: {{ $labels.namespace }} | Pod名称: {{ $labels.pod }} 内存使用大于85% (当前值: {{ $value }})"
[root@pro-k8s-master ~]# kubectl -n msApp get pod -o wide|grep mayi
mayi-center-9d5d588c5-d7sgd 1/1 Running 0 7d 10.100.235.43 k8s-node1 <none> <none>
mayi-center-9d5d588c5-mzd9p 1/1 Running 0 7d 10.100.6.41 k8s-node2 <none> <none>
[root@k8s-node1 ~]# docker ps |grep mayi-center-9d5d588c5-d7sgd
[root@pro-node1 ~]# docker ps |grep mayi-center-9d5d588c5-d7sgd
b6b3733024c2 192.168.0.45/middleground-business-center/pro_mayi-center "sh -c 'JAVA $JAVA_O…" 7 days ago Up 7 days k8s_mayi-center_mayi-center-9d5d588c5-d7sgd_msapp_eac4e708-bd0a-483c-b5d4-734f95c9f1c7_0
5770fe14e7aa registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 "/pause" 7 days ago Up 7 days k8s_POD_mayi-center-9d5d588c5-d7sgd_msapp_eac4e708-bd0a-483c-b5d4-734f95c9f1c7_0
[root@k8s-node1 ~]#docker state b6b3733024c2
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % .NET I/O BLOCK I/O PIDS
b6b3733024c2 k8s_mayi-center_mayi-center-9d5d588c5-d7sgd_msapp_eac4e708-bd0a-483c-b5d4-734f95c9f1c7_0 4.31% 1.788GiB / 2GiB 89.40% 0B / 0B 1.52MB / 137MB 132
[root@pro-k8s-node1 ~]# top -p 794890
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
794890 root 20 0 7483084 1.8g 15448 S 6.7 2.9 392:48.42 java
[root@pro-k8s-node1 ~]# ps -ef|grep mayi
root 277280 257311 0 10:33 pts/0 00:00:00 grep --color=auto mayi
root 794890 794871 3 Sep08 ? 06:32:39 java -XX:+UseContainerSupport .....mayi-center ..... -jar /app.jar
[root@pro-k8s-node1 ~]# ps -e -o 'pid,comm,args,pcpu,rsz,vsz,stime,user,uid' | grep 794890
279183 grep grep --color=auto 794890 0.0 960 112712 10:35 root 0
794890 java java -XX:+UseContainerSuppo 3.8 1883224 7483084 Sep08 root 0
通过arthas-boot 查看堆内存和非堆内存
1、通过top查看到容器内对应java进程占用内存为1.8G,跟prometheus几乎一致
2、通过ps 查看到容器内对应java进程占用内存为1.8G+,跟prometheus几乎一致
3、通过docker state 查看到容器内存查看内存内存为1.8G+,跟prometheus几乎一致
4、通过arthas-boot查看到jvm堆内存和非堆内存之和为1.6G+。
由于通过prometheus pod内存告警和实际jvm查看到的内存不同带来的疑问,初步怀疑是jvm本身占用了部分内存。