OOM 如何监控可视化、告警推送、服务自愈

OOMout of memorykernelOOM killer

OOMOOMOOM

OOMOOMmallocmmapENOMEM

kernel OOM

OOM

1 node_export + grafna +  prometheus + alertmanager  

1.1node_export  --collector.vmstat

/opt/exporter/bin/node_exporter_51233 --web.listen-address=0.0.0.0:51233 --collector.cpu.info --collector.arp --collector.cpu --collector.diskstats --collector.filesystem --collector.loadavg --collector.meminfo --collector.mountstats --collector.nfs --collector.stat --collector.tcpstat --collector.vmstat

1.2grafna PromQL  OOM 

-- oom 频率increase(node_vmstat_oom_kill{host=~"$host"}[1m])
-- oom 总次数node_vmstat_oom_kill > 0

1.3 prometheus  rules oom 

 /opt/prometheus/rules/node_rules.yml  oom 

 ##alert for host oom
  - alert: IOV-HostOomKillDetected
    expr: increase(node_vmstat_oom_kill[1m]) > 0
    for: 0m
    labels:
      level: 3
    annotations:
      cur_value: '{{ $value }}'
      description: "OOM kill detected"

 1.4alertmanager 

alertmanager.yml 

2systemd

systemdOOMkill -9,

RestartPreventExitStatus  

systemd[Service]RestartPreventExitStatus

退

exit code2

  RestartPreventExitStatus=143 137 SIGTERM SIGKILL

[Unit]
  Description=mytest
  [Service]
  Type=simple
  ExecStart=/root/mytest.sh
  Restart=always
  RestartSec=5
  StartLimitInterval=0
  [Install]
  WantedBy=multi-user.target

重点参数详解
Restart=always: 只要不是通过systemctl stop来停止服务,任何情况下都必须要重启服务,默认值为no
RestartSec=5: 重启间隔,比如某次异常后,等待5(s)再进行启动,默认值0.1(s)
StartLimitInterval: 无限次重启,默认是10秒内如果重启超过5次则不再重启,设置为0表示不限次数重启

 

 

 

 

posted on 2023-06-09 15:10  张冲andy  阅读(35)  评论(0编辑  收藏  举报

导航