因zabbix自带监控JMX的模板通用性差的问题,需要我们自己新建一个属于自己的模板,于是本文就出现了。。。。
大部分都是参考网上其他博主的文档,在此作为梳理、总结;以方便自己日后使用查询。
chmod +s grep
模版位置:
链接:https://pan.baidu.com/s/1r7YrlL-6Z_I3mIYsL1CTQg
提取码:ep7d
脚本内容如下:
#!/bin/bash #t_datadir=`find /usr/local/ -maxdepth 1 -name "*_apache" -type d` t_datadir=`find /usr/local/ -maxdepth 1 -name "*_apache" -type d | awk -F '/' '{print $4}'` local_ip1=`ifconfig em2 |awk -F '[ :]+' 'NR==2 {print $4}'` #tomcat_no=`find /usr/local/ -maxdepth 1 -name "*_apache" -type d |wc -l` declare -a AAA=() declare -a BBB=() a=0 for i in ${t_datadir} do { n_ports=`/bin/grep Dcom.sun.management.jmxremote.port /usr/local/$i/bin/catalina.sh|awk -F "=" '{print $2}'` if [ "${n_ports}" ];then AAA[a]="$i" BBB[a]="${n_ports}" let "a=a+1" fi } done declare -i d=${#AAA[@]} let "d=d-1" printf '{"data":[ ' for ((i=0;i<${#AAA[@]};i++)) do # echo "----$i----${AAA[$i]}----${BBB[$i]}" # if [ $i -eq $d ];then # echo '====' # fi if [ $i -eq $d ];then printf " { " printf " "{#SERVER_IP}":"${local_ip1}", " printf " "{#JMX_PORT}":"${BBB[$i]}", " printf " "{#JAVA_NAME}":"${AAA[$i]}"}]} " else printf " { " printf " "{#SERVER_IP}":"${local_ip1}", " printf " "{#JMX_PORT}":"${BBB[$i]}", " printf " "{#JAVA_NAME}":"${AAA[$i]}"}, " fi done