当前位置:网站首页>A ZABBIX self discovery script (shell Basics)
A ZABBIX self discovery script (shell Basics)
2022-06-26 04:42:00 【Half crazy and half bumpy】
1. To configure zabbix Related configuration :
#dis
UserParameter=h5discovery.game, bash /data/app/zabbix/agentscript/discovery_Game.sh
#base
UserParameter=h5proc.mem[*], bash /data/app/zabbix/agentscript/H5_discovery_Game.sh mem $1 2>&1
UserParameter=h5proc.cpu[*], bash /data/app/zabbix/agentscript/H5_discovery_Game.sh cpu $1 2>&1
UserParameter=h5proc.state[*], bash /data/app/zabbix/agentscript/H5_discovery_Game.sh state $1 2>&1
Used to monitor cpu, Memory and process status
2. Self discovery script :
[email protected]:-6-$ cat /data/app/zabbix/agentscript/discovery_Game.sh
#!/bin/bash
DIR="/data/server/bin"
t=0
A=()
FLAG=$2
WathFile=`find ${DIR} -type f -name "*Watch*.ini" `
for i in ${WathFile}
do
A[${t}]=`cat ${i}|grep -E "(gamename|enable)"|awk -F\= '{print $NF}'`
B[${t}]=`cat ${i}|grep -i "port"|awk -F\= '{print $2}'`
let t++
done
sub_dis() {
printf "{\n"
printf '\t"data":[\n'
for((j=0;j
do
num=`echo $((${#A[@]}-1))`
if [ $j -ne $num ];then
printf "\t\t{ \n"
printf "\t\t\t\"{#SVRNAME}\":\"${A[$j]}\",\\n"
printf "\t\t\t\"{#SVRPORT}\":\"${B[$j]}\"},\n"
else
printf "\t\t{\n"
printf "\t\t\t\"{#SVRNAME}\":\"${A[$j]}\",\\n"
printf "\t\t\t\"{#SVRPORT}\":\"${B[$j]}\"}]}\n"
fi
done
}
sub_mem() {
PortNum=`echo ${FLAG}|awk -F \, '{print NF}'`
if [ $PortNum -eq 1 ];then
GamePid=`sudo netstat -ntlp|grep ${FLAG}|awk '{printf $7}'|cut -d/ -f1`
num=`ps aux|grep ${GamePid}|grep -v grep |awk '{print $6}'`
else
GamePort=`echo ${FLAG}|awk -F \, '{print $1}'`
GamePid=`sudo netstat -ntlp|grep ${GamePort}|awk '{printf $7}'|cut -d/ -f1`
num=`ps aux|grep ${GamePid}|grep -v grep |awk '{print $6}'`
fi
if [[ -z ${num} ]]
then
echo 0
else
echo ${num}
fi
}
sub_cpu() {
PortNum=`echo ${FLAG}|awk -F \, '{print NF}'`
if [ $PortNum -eq 1 ];then
GamePid=`sudo netstat -ntlp|grep ${FLAG}|awk '{printf $7}'|cut -d/ -f1`
num=`ps aux|grep ${GamePid}|grep -v grep |awk '{print $3}'`
else
GamePort=`echo ${FLAG}|awk -F \, '{print $1}'`
GamePid=`sudo netstat -ntlp|grep ${GamePort}|awk '{printf $7}'|cut -d/ -f1`
num=`ps aux|grep ${GamePid}|grep -v grep |awk '{print $3}'`
fi
if [[ -z ${num} ]]
then
echo 0
else
echo ${num}
fi
}
sub_state() {
PortNum=`echo ${FLAG}|awk -F \, '{print NF}'`
if [ $PortNum -eq 1 ];then
Proc=`sudo netstat -ntlp|grep -v grep |grep ${FLAG}`
else
GamePort=`echo ${FLAG}|awk -F \, '{print $1}'`
Proc=`sudo netstat -ntlp|grep -v grep |grep ${GamePort}`
fi
if [[ -n ${Proc} ]]
then
echo "1"
else
echo "0"
fi
}
case "$1" in
mem)
sub_mem
;;
state)
sub_state
;;
cpu)
sub_cpu
;;
*)
sub_dis
exit 6
esac
边栏推荐
- How can the intelligent transformation path of manufacturing enterprises be broken due to talent shortage and high cost?
- Thinkphp6 parsing QR code
- 2022.2.16
- 08_SpingBoot 集成Redis
- Mysql8.0 configuring my SQL in INI file_ mode=NO_ AUTO_ CREATE_ User can start
- Advanced learning of MySQL (learning from Shang Silicon Valley teacher Zhou Yang)
- PHP splits a string into arrays
- PHP installation SSH2 extension
- A troubleshooting of website crash due to high CPU
- Oracle 數據泵導錶
猜你喜欢
Text horizontal alignment attribute text align and element vertical alignment attribute vertical align
Advanced learning of MySQL (learning from Shang Silicon Valley teacher Zhou Yang)
#微信小程序# 在小程序里面退出退出小程序(navigator以及API--wx.exitMiniProgram)
Use of better scroll
1.19 learning summary
Differences between TCP and UDP
0622-马棕榈跌9%
Install Damon database
Your requirements could not be resolved
1.24 learning summary
随机推荐
Thymeleaf data echo, single selection backfill, drop-down backfill, time frame backfill
排序查询
2022.2.15
Multipass中文文档-提高挂载性能
Rsync common error messages (common errors on the window)
Install Damon database
Redis cluster mode
1.18 learning summary
文件上传与安全狗
Thinkphp6 parsing QR code
A method of quickly transplanting library function code to register code by single chip microcomputer
2022.2.11
Tips for using idea
Sixtool- source code of multi-functional and all in one generation hanging assistant
Guide de la pompe de données Oracle
Nightmare
1.14 learning summary
Laravel framework Alipay payment fails to receive asynchronous callback request [original]
numpy 随机数
Introduction to markdown grammar