1-进程监控
1-1 在agent端编写脚本 取出需要监控资源的状态值
//创建目录
[root@localhost ~]# mkdir /scripts
//编写内容脚本
[root@localhost ~]# vim /scripts/check_process.sh
[root@localhost ~]# cat /scripts/check_process.sh
#!/bin/bash
status=$(ps -ef |grep $1|grep -Ev "$0|grep"|wc -l)
if [ $status -eq 0 ];then
echo '1'
else
echo '0'
fi
//给执行权限
[root@localhost ~]# chmod +x /scripts/check_process.sh
//查看
[root@localhost ~]# ll /scripts/check_process.sh
-rwxr-xr-x 1 root root 134 Sep 6 21:23 /scripts/check_process.sh
1-2 在agent端编写配置文件
//将下面两行取消注释作修改,或者直接添加这两行
[root@localhost ~]# vim /usr/local/etc/zabbix_agentd.conf
# Mandatory: no
# Range: 0-1
# Default:
UnsafeUserParameters=1 //取消注释 改为1
### Option: UserParameter
# User-defined parameter to monitor. There can be several user-defined parameters.
# Format: UserParameter=<key>,<shell command>
# See 'zabbix_agentd' directory for examples.
#
# Mandatory: no
# Default:
UserParameter=check_process[*],/bin/bash /scripts/check_process.sh $1 //取消注释写入内容
//重启agent,生效作更改的配置
[root@localhost ~]# pkill zabbix_agentd
[root@localhost ~]# zabbix_agentd
[root@localhost ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
//安装httpd服务
[root@localhost ~]# yum -y install httpd
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:10050