自定义监控进程和自定义监控日志

 

基于昨天的邮箱告警,部署完成后,我们可以编译脚本用来监控进程
首先我们可以在被监控端,开启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]# 

<

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值