创建的自定义脚本:

[[email protected] zabbix_agentd.d]# cat crm-web.sh 
#!/bin/bash
ps -ef|grep crm-web|grep -v 'grep'|grep -v 'sh'|wc -l

  注意权限和用户:

[[email protected] zabbix_agentd.d]# ll crm-web.sh 
-rwxr-xr-x 1 zabbix zabbix 66 Nov 18 14:55 crm-web.sh

  创建的自定义key:

[[email protected] zabbix_agentd.d]# cat crm-web_status.conf 
UserParameter=crm-web_status[*],/etc/zabbix/zabbix_agentd.d/crm-web.sh $1

  注意权限和用户:(应该不需要调整)

[[email protected] zabbix_agentd.d]# ll crm-web_status.conf 
-rw-r--r-- 1 root root 74 Nov 18 13:03 crm-web_status.conf

  .conf文件必须被包含在agent配置文件里,zabbix服务端才能最终识别。

[[email protected] zabbix_agentd.d]# cat /etc/zabbix/zabbix_agentd.conf
LogFile=/tmp/zabbix_agentd.log
Server=10.253.40.87
ServerActive=10.253.40.87
Hostname=10.253.40.84
RefreshActiveChecks=300
BufferSend=5
BufferSize=1000
MaxLinesPerSecond=200
Timeout=10
#Include=/etc/zabbix/zabbix_agentd.d/*.conf
Include=/etc/zabbix/scripts/redis_status.conf
Include=/etc/zabbix/scripts/check_redis.conf
Include=/etc/zabbix/zabbix_agentd.d/activemq_process.conf


UnsafeUserParameters=1
UserParameter=redis_stats[*],/usr/local/redis/src/redis-cli -h 127.0.0.1 -p $1 -a 8%Hoq1*_4y info|grep $2|cut -d : -f2
UserParameter=await[*],/usr/bin/tail /tmp/iostat_output |grep "\b$1\b" |tail -1|awk '{print $$10}'
UserParameter=svctm[*],/usr/bin/tail /tmp/iostat_output |grep "\b$1\b" |tail -1|awk '{print $$11}'
UserParameter=util[*],/usr/bin/tail /tmp/iostat_output |grep "\b$1\b" |tail -1|awk '{print $$12}'

  重启zabbix agent服务:

[[email protected] zabbix_agentd.d]# ps -ef|grep zabbix
zabbix    5534     1  0 14:17 ?        00:00:00 zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
zabbix    5535  5534  0 14:17 ?        00:00:00 zabbix_agentd: collector [idle 1 sec]
zabbix    5536  5534  0 14:17 ?        00:00:00 zabbix_agentd: listener #1 [waiting for connection]
zabbix    5537  5534  0 14:17 ?        00:00:00 zabbix_agentd: listener #2 [waiting for connection]
zabbix    5538  5534  0 14:17 ?        00:00:00 zabbix_agentd: listener #3 [waiting for connection]
zabbix    5539  5534  0 14:17 ?        00:00:00 zabbix_agentd: active checks #1 [idle 1 sec]
root      9386 30370  0 14:59 pts/4    00:00:00 grep --color=auto zabbix
[[email protected] zabbix_agentd.d]# pkill -f /etc/zabbix/zabbix_agentd.conf
[[email protected] zabbix_agentd.d]# ps -ef|grep zabbix
root      9410 30370  0 14:59 pts/4    00:00:00 grep --color=auto zabbix
[[email protected] zabbix_agentd.d]# zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
[[email protected] zabbix_agentd.d]# ps -ef|grep zabbix
zabbix    9420     1  0 14:59 ?        00:00:00 zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
zabbix    9421  9420  0 14:59 ?        00:00:00 zabbix_agentd: collector [idle 1 sec]
zabbix    9422  9420  0 14:59 ?        00:00:00 zabbix_agentd: listener #1 [waiting for connection]
zabbix    9423  9420  0 14:59 ?        00:00:00 zabbix_agentd: listener #2 [waiting for connection]
zabbix    9424  9420  0 14:59 ?        00:00:00 zabbix_agentd: listener #3 [waiting for connection]
zabbix    9425  9420  0 14:59 ?        00:00:00 zabbix_agentd: active checks #1 [idle 1 sec]
root      9434 30370  0 14:59 pts/4    00:00:00 grep --color=auto zabbix


选择“Configuration”→“Host”

简单的自定义监控linux服务,只看ps进程是否存在



找到指定的监控主机,选择“Items”

简单的自定义监控linux服务,只看ps进程是否存在

在弹出的新界面,点击“Create item”按纽

简单的自定义监控linux服务,只看ps进程是否存在


只需要修改“Name”和“Key”值

◆Namecrm-web服务进程

◆Keycrm-web_status

简单的自定义监控linux服务,只看ps进程是否存在


“applications”并非必选项,可以根据自己的实际情况来决定,这里主要方便分类。

简单的自定义监控linux服务,只看ps进程是否存在

点击“Triggers”,就可以点击“Create trigger”按纽

简单的自定义监控linux服务,只看ps进程是否存在


在弹出的新界面里,填写内容如下:

◆“Name”:crm-web服务不可用

◆“Expression”:{10.253.40.86:crm-web_status.last()}<>1

◆“Description”:crm-web服务不可用【不是必须填写的内容】

◆“Severity”:也不是必须这种类型

简单的自定义监控linux服务,只看ps进程是否存在


“Expression”里的内容,是点击“Add”按纽,在弹出的对话框里,再点击“Select”按纽

简单的自定义监控linux服务,只看ps进程是否存在


  在弹出的对话框里,点击“crm-web服务进程”。这里之所以有这个监控项,是因为前面创建过Item,否则,自定义的监控项不会出现在这里。如果没有,也可以查看一下右上角的“Group”和“Host”定位是否正确。

简单的自定义监控linux服务,只看ps进程是否存在


“Function”选项就用图中的参数

“N”选项:1

简单的自定义监控linux服务,只看ps进程是否存在


点击“Graphs”,再点击“Create graph”按纽

简单的自定义监控linux服务,只看ps进程是否存在


“Name”:crm-web服务进程

简单的自定义监控linux服务,只看ps进程是否存在


点击“Add”按纽,在弹出的对话框里选择“crm-web服务进程”即可

简单的自定义监控linux服务,只看ps进程是否存在

  基本的配置就这些内容。


  下面的自定义监控项几乎一样:

[[email protected] zabbix_agentd.d]# cat crm-notify.sh 
#!/bin/bash
ps -ef|grep crm-notify|grep -v 'grep'|grep -v 'sh'|wc -l
[[email protected] zabbix_agentd.d]# cat crm-notify_status.conf 
UserParameter=crm-notify_status[*],/etc/zabbix/zabbix_agentd.d/crm-notify.sh $1

  不要忘了重启zabbix agent服务。


  在zabbix服务端执行测试命令:

[[email protected] zabbix_agentd.d]# zabbix_get -s 10.253.40.86 -k "crm-web_status"
1
[[email protected] zabbix_agentd.d]# zabbix_get -s 10.253.40.86 -k "crm-notify_status"
1


转载于:https://blog.51cto.com/gagarin/1874406

相关文章: