1、监控服务端口配置文件:
UserParameter=im.port.discovery,/bin/bash /data/scripts/process_discovery.sh
代码语言:javascript复制监控端口的脚本:
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 "tt{ n"
port=`echo ${process[$i]}|awk -F "," '{print $2}'`
process_name=`echo ${process[$i]}|awk -F "," '{print $1}'`
printf "ttt"{#PORT}":"$port",n"
printf "ttt"{#PROCESS_NAME}":"$process_name"n"
printf "tt},n"
else
printf "tt{ n"
port=`echo ${process[$i]}|awk -F "," '{print $2}'`
process_name=`echo ${process[$i]}|awk -F "," '{print $1}'`
printf "ttt"{#PORT}":"$port",n"
printf "ttt"{#PROCESS_NAME}":"$process_name"n"
printf "tt}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
代码语言:javascript复制监控服务的脚本:
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 "tt{ n"
printf "ttt"{#PROCESS}":"${process[$i]}"},n"
else
printf "tt{ n"
#printf "tt n"
printf "ttt"{#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配置截图:
=====