当前位置:网站首页>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>&1Used 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边栏推荐
- Laravel uses phpword to generate word documents
- ROS 笔记(07)— 客户端 Client 和服务端 Server 的实现
- Svn error command revert error previous operation has not finished; run ‘ cleanup‘ if
- Use of better scroll
- Yapi cross domain request plug-in installation
- Multipass中文文档-设置驱动
- "Eight hundred"
- Simple personal summary of tp6 multi application deployment -- Part I [original]
- 22.2.8
- Rdkit chemical formula molecular formula search
猜你喜欢

Yapi cross domain request plug-in installation

Mysql8.0 configuring my SQL in INI file_ mode=NO_ AUTO_ CREATE_ User can start

Thinkphp6 implements a simple lottery system

Gateway can not connect to tcp://127.0.0.1: Connection refused

Use of better scroll

Install Damon database

SixTool-多功能多合一代挂助手源码

Zhimeng CMS will file a lawsuit against infringing websites

Rdkit chemical formula molecular formula search

Sixtool- source code of multi-functional and all in one generation hanging assistant
随机推荐
Mysql8.0 configuring my SQL in INI file_ mode=NO_ AUTO_ CREATE_ User can start
A method of quickly transplanting library function code to register code by single chip microcomputer
防撤回测试记录
Sort query
Alipay failed to verify the signature (sandbox test indicates fishing risk?) [original]
Dameng database backup and restore
202.2.9
08_SpingBoot 集成Redis
2021/11/6-burpsuit packet capturing and web page source code modification
The statistics in the MySQL field become strings, and then they are converted into numbers for sorting
SSH password free login, my server password free login to the other server, the other server password free login to your server
1.12 learning summary
mysql高级学习(跟着尚硅谷老师周阳学习)
2.8 learning summary
Laravel file stream download file
微信小程序保存图片的方法
An unexpected attempt (Imperial CMS list template filters spaces and newlines in smalltext introduction)
基础查询
PHP installation SSH2 extension
[H5 development] 03- take you hand in hand to improve H5 development - single submission vs batch submission with a common interface