基于昨天的邮箱告警,部署完成后,我们可以编译脚本用来监控进程
首先我们可以在被监控端,开启httpd服务,以便监控
配置监控脚本
#重启服务,生效配置
[root@localhost ~]# pkill zabbix
[root@localhost ~]# zabbix_agentd
[root@web ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
#先安装一个可监控的进程
[root@web ~]#
[root@web ~]# cd /usr/local/etc/
[root@web etc]# yum -y install httpd
[root@web etc]# systemctl start httpd.service
[root@web etc]# ps -ef | grep httpd | wc -l
6
[root@web etc]# ps -ef | grep -v grep | grep httpd | wc -l
5
#再编写脚本
[root@web ~]# mkdir /scripts
[root@web scripts]#
[root@web scripts]# vim check_httpd.sh
[root@web scripts]# cat check_httpd.sh
#!/bin/bash
count=$(ps -ef | grep -Ev "grep|$0" | grep httpd | wc -l )
if [ $count -eq 0 ];then
echo '1'
else
echo '0'
fi
[root@web scripts]# ll check_httpd.sh
-rw-r--r--. 1 root root 133 Sep 6 23:29 check_httpd.sh
[root@web scripts]# chmod +x check_httpd.sh
[root@web scripts]# ll check_httpd.sh
-rwxr-xr-x. 1 root root 133 Sep 6 23:29 check_httpd.sh
[root@web scripts]# ./check_httpd.sh
0
[root@web scripts]# systemctl stop httpd.service
[root@web scripts]# ./check_httpd.sh
1
#监控多个进程
[root@web scripts]# mv check_httpd.sh check_process.sh
[root@web scripts]# ls
check_process.sh
[root@web scripts]# vim check_process.sh
[root@web scripts]# cat check_process.sh
#!/bin/bash
count=$(ps -ef | grep -Ev "grep|$0" | grep $1 | wc -l )
if [ $count -eq 0 ];then
echo '1'
else
echo '0'
fi
[root@web scripts]# ./check_process.sh httpd
0
[root@web scripts]# ./check_process.sh mysql
1
[root@web scripts]#
<