Use the JSTAT-GC TOMCAT ID to reorder the data into the $tomcat file, looping through
But jstat this command requires the same privileges as Tomcat to start the user Zabbix, you can start the zabbix-agent using the same user as the Tomcat startup user, or you can Visudo
[Root@iz62bxn7uuzz scripts]# Cat jstat.sh
#!/bin/bash
# -------------------------------------------------------------------------------
# -------------------------------------------------------------------------------
# Notice
# Apply Zabbix version 2.4.x to 3.0.3
# Auto Search jmx pid
# You need to understand:
# jstat.sh Search pid;jvm_name.sh Search tomcat name;jvm_status.sh obtain $ transfer
# Automatic Discovery jmx monitoring. It applies only to JSTAT-GC pid it
#################################################################################
Tomcat_name= ' Ps-ef | grep Tomcat | Grep-v grep | Grep-v "Jvm_status.sh" | Awk-f "=" ' {print $NF} ' | Cut-d "/" F 3 '
For T in ${tomcat_name[@]};d o
T_id= ' Ps-ef | grep "$t/" | Grep-v "grep" | awk ' {print $} '
/USR/JAVA/JDK1.7.0_79/BIN/JSTAT-GC $t _id | awk ' begin{fs= '}{for (i = 1;i <= nf;i++) {array[i,nr]= $i}}end {for (i = 1;i <= nf;i++) {for (j = 1;j <= nr;j++) {p rintf "%s", array[i,j]}printf "\ n"} >/tmp/"$t". GC
Done
Automatically discovers Tomcat path, named by Path
[Root@iz62bxn7uuzz scripts]# Cat jvm_name.sh
#!/bin/bash
# -------------------------------------------------------------------------------
# -------------------------------------------------------------------------------
# Notice
# Apply Zabbix version 2.4.x to 3.0.3
# Auto Search jmx name.
# You need to understand:
# jstat.sh Search pid;jvm_name.sh Search tomcat name;jvm_status.sh obtain $ transfer
# Automatic Discovery jmx monitoring. It applies only to JSTAT-GC pid it
#################################################################################
Tomcat_name= ' Ps-ef | grep Tomcat | Grep-v grep | Awk-f "=" ' {print $NF} ' | Cut-d "/" F 3 '
Falg=0
Count= ' Ps-ef | grep Tomcat | Grep-v grep | Wc-l '
if [$count = 0];then
Exit
Fi
Echo ' {' Data ': ['
echo "$tomcat _name" |while Read Line;do
Echo-n ' {' {#JVMNAME} ': ' $LINE '} '
flag= ' expr $flag + 1 '
If [$flag-lt $count];then
Echo ', '
Fi
Done
Echo ']} '
Here you can actually abbreviate:
[Root@iz62bxn7uuzz scripts]# Cat jvm_status.sh
#!/bin/bash
# -------------------------------------------------------------------------------
# Filename:jvm_status.sh
# -------------------------------------------------------------------------------
# Notice
# Apply Zabbix version 2.4.x to 3.0.3
# Auto Search jmx Name
# You need to understand:
# jstat.sh Search pid;jvm_name.sh Search tomcat name;jvm_status.sh obtain $ transfer
# Automatic Discovery jmx monitoring. It applies only to JSTAT-GC pid it
#################################################################################
T=$1
Jvm_key=$2
cat/tmp/"$t". GC | Grep-w "$JVM _key" | awk ' {print $} '
Randomly filter the number of HTTP threads:
jvm_thread_num.sh
#!/bin/sh
Jvmname=$1
Pid= ' Ps-ef | grep "$jvmname" | Grep-v grep | Grep-v "$" | awk ' {print $} '
jvm_status= ' sudo-u ody/usr/local/java/jdk1.7.0_80/bin/jstack "$pid" >/data/zabbix/shell/jstack.txt '
function all {
Cat/data/zabbix/shell/jstack.txt | grep http|wc-l
}
function runnable {
Cat/data/zabbix/shell/jstack.txt | grep http|grep Runnable|wc-l
}
$
Add to the configuration file:
userparameter=jvm.name,/usr/local/zabbix/scripts/jvm_name.sh
Userparameter=jvm.thread.num[*],/usr/local/zabbix/scripts/jvm_thread_num.sh $ $
Userparameter=jvm.status[*],/usr/local/zabbix/scripts/jvm_status.sh $ $
Schedule a recurring script append file per minute in the scheduled task to keep the current status per minute
*/1 * * * */bin/bash/usr/local/zabbix/scripts/jstat.sh 2>/dev/null
Jstat
Check_mode () {
Tomcat_name= ' Ps-ef | grep Tomcat | Grep-v grep | Grep-v "Jvm_status.sh" | Awk-f "=" ' {print $NF} ' | Cut-d "/" F 3 '
For T in ${tomcat_name[@]};d o
T_id= ' Ps-ef | grep "$t/" | Grep-v "grep" | awk ' {print $} '
/USR/JAVA/JDK1.7.0_79/BIN/JSTAT-GC $t _id | \
awk ' begin{fs= '}{for (i=1;i<=nf;i++) {array[i,nr]= $i}}end {for (i = 1;i <= nf;i++) {for (j = 1;j <= nr;j++) {print F '%s ', array[i,j]}printf ' \ n '} ' >/tmp/' $t. GC
Done
}
While:; Todo
Check_mode
Sleep 60
Done