1、监控服务端口配置文件:
UserParameter=im.port.discovery,/bin/bash /data/scripts/process_discovery.sh
监控端口的脚本:
cat /data/scripts/process_discovery.sh
#!/bin/bash
process_discovery () {
process=($(cat /data/scripts/process.txt))
printf '{\n'
printf '\t"data":[\n'
for((i=0;i<${#process[@]};++i))
{
num=$(echo $((${#process[@]}-1)))
if [ "$i" != ${num} ];then
printf "\t\t{ \n"
port=`echo ${process[$i]}|awk -F "," '{print $2}'`
process_name=`echo ${process[$i]}|awk -F "," '{print $1}'`
printf "\t\t\t\"{#PORT}\":\"$port\",\n"
printf "\t\t\t\"{#PROCESS_NAME}\":\"$process_name\"\n"
printf "\t\t},\n"
else
printf "\t\t{ \n"
port=`echo ${process[$i]}|awk -F "," '{print $2}'`
process_name=`echo ${process[$i]}|awk -F "," '{print $1}'`
printf "\t\t\t\"{#PORT}\":\"$port\",\n"
printf "\t\t\t\"{#PROCESS_NAME}\":\"$process_name\"\n"
printf "\t\t}\n"
printf "]\n"
printf "}\n"
fi
}
}
process_discovery
cat /data/scripts/process.txt
jenkins,8080
执行结果:
/bin/bash /data/scripts/process_discovery.sh
{
"data":[
{
"{#PORT}":"8080",
"{#PROCESS_NAME}":"jenkins"
}
]
}
2、监控服务端置文件:
UserParameter=process.discovery,/bin/bash /data/scripts/pro_discovery.sh
UserParameter=pro.check[*],ps -ef|grep -w $1|grep -v grep|wc -l
监控服务的脚本:
cat /data/scripts/pro_discovery.sh
#!/bin/bash
process_discovery () {
process=($(cat /data/scripts/pro.config))
printf '{\n'
printf '\t"data":[\n'
for((i=0;i<${#process[@]};++i))
{
num=$(echo $((${#process[@]}-1)))
if [ "$i" != ${num} ];then
printf "\t\t{ \n"
printf "\t\t\t\"{#PROCESS}\":\"${process[$i]}\"},\n"
else
printf "\t\t{ \n"
#printf "\t\t \n"
printf "\t\t\t\"{#PROCESS}\":\"${process[$i]}\"}\n"
printf "]\n"
printf "}\n"
fi
}
}
process_discovery $1
cat /data/scripts/pro.config
/data2/java/servers/web_newuploadsystem_9070/conf/logging.properties
zabbix配置截图:
=====