chriszg 发表于 2019-1-19 09:49:59

zabbix监控CPU等资源报警到163邮箱

  监控cpu报警:
  
  zabbix自带模板有一个 Template OS Linux模板。这个模板有监控CPU的监控项,如果没有添加一个监控项“ CPU idle time”
这个监控项监控的是CPU剩余的时间。监控到这个指标也就可以监控到使用了多少。
1、首先,如果没有添加一个监控项“ CPU idle time”,具体步骤如下:
1、1:配置—>模板—->找到Template OS Linux模板—监控项
http://s1.运维网.com/images/20180702/1530499654665722.png
  创建监控项:
http://s1.运维网.com/images/20180702/1530499669620564.png
  内容如下:
  http://s1.运维网.com/images/20180702/1530499681544546.png
  备注这个一般没有需要创建才可以使用:
   http://s1.运维网.com/images/20180702/1530499697125450.png
  创建触发器:

   http://s1.运维网.com/images/20180702/1530499738952167.png

  http://s1.运维网.com/images/20180702/1530499749996448.pnghttp://s1.运维网.com/images/20180702/1530499763112863.png
  http://s1.运维网.com/images/20180702/1530499775246530.png
  接下来时创建图形:图形可以自己定义,如果有现成的可以直接复制一份进行使用

   http://s1.运维网.com/images/20180702/1530499795614849.png

  http://s1.运维网.com/images/20180702/1530499806560373.png
  这里克隆一份不破坏之前的
  
   http://s1.运维网.com/images/20180702/1530499821309726.png
  http://s1.运维网.com/images/20180702/1530499852710857.png
  完事后就可以查看一下
  http://s1.运维网.com/images/20180702/1530499875116576.png http://s1.运维网.com/images/20180702/1530499891737967.png

  接下来配置邮件服务开始报警,我们使用163的邮箱
   http://s1.运维网.com/images/20180702/15304×××3882686.pnghttp://s1.运维网.com/images/20180702/1530499940801192.png

  一定要创建动作,如果没有那上面的就是白搭相当于没做
   http://s1.运维网.com/images/20180702/1530499952781653.png
  创建操作
  http://s1.运维网.com/images/20180702/1530499976532378.png
  
  创建恢复:和上面一样
  http://s1.运维网.com/images/20180702/1530499990256634.png
  确认操作也和上面一样:
   http://s1.运维网.com/images/20180702/1530500002477996.png
  等着一切都完成之后进行添加在动作里面
  http://s1.运维网.com/images/20180702/1530500033685883.png
   http://s1.运维网.com/images/20180702/1530500046738474.png

  接下来在服务器上面进行操作
  需要安装mail服务
  yum install mailx
  vi /etc/mail.rc
  添加这三行
   http://s1.运维网.com/images/20180702/1530500061891573.png
  set from=lxftty@163.com smtp=smtp.163.com
  set smtp-auth-user=lxftty@163.com smtp-auth-password=xxxxx
  set smtp-auth=login
  
  
  创建脚本文件:
  vi /usr/lib/zabbix/alertscripts/sendmail.sh
   http://s1.运维网.com/images/20180702/1530500087997437.png
  touch /tmp/mailtmp.txt
  chown zabbix.zabbix /tmp/mailtmp.txt
  chmod 755 /usr/lib/zabbix/alertscripts/sendmail.sh
  
  
  测试一下:
  echo "zabbix test mail" |mail -s "zabbix" lxftty@163.com
  
   http://s1.运维网.com/images/20180702/1530500105935779.png

  接下来开始cpu超过80%报警:
  for i in `seq 1 $(cat /proc/cpuinfo |grep "physical id" |wc -l)`; do dd if=/dev/zero of=/dev/null & done
   http://s1.运维网.com/images/20180702/1530500127837163.png
  http://s1.运维网.com/images/20180702/1530500142337337.png
  测试一下

  看看邮件
  http://s1.运维网.com/images/20180702/1530500159600686.png
  当我们吧cpu降低下来再看看那
http://s1.运维网.com/images/20180702/1530500466376751.png
  如果其中一台服务的zabbix-agent连接不到也会报警
  
   http://s1.运维网.com/images/20180702/1530500198998351.png
  http://s1.运维网.com/images/20180702/1530500214848571.png
  启动之后就会好了



页: [1]
查看完整版本: zabbix监控CPU等资源报警到163邮箱