forked from noamik/wildfly-jvm-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitor-jvm-limits.sh
executable file
·149 lines (135 loc) · 4.37 KB
/
monitor-jvm-limits.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/bash
FPID="/opt/jvm-monitor/pids"
HOST=$(hostname)
TIMESTAMP=0
JPPID=""
JHPID=""
JSPID1=""
JSPID2=""
FIRST=true
JHSTAT=()
JPSTAT=()
JSTAT1=()
JSTAT2=()
SENDING_DATA=""
JHRUN=1
JPRUN=1
JS1RUN=1
JS2RUN=1
LOG="/tmp/jvm-monitor.log"
ZABBIX_AGENTD_CONF="/etc/zabbix/zabbix_agentd.conf"
function getPids {
JPPID=$(<$FPID/process-controller.pid)
JHPID=$(<$FPID/host-controller.pid)
JSPID1=$(<$FPID/slave-100.pid)
JSPID2=$(<$FPID/slave-200.pid)
}
function getJstat {
if [ -n "$1" ]; then
TIMESTAMP=$(date +%s)
if [[ $platform == 'sunos' ]]; then
/opt/local/bin/sudo /opt/local/java/openjdk7/bin/jstat -gccapacity -t $1
else
sudo -H -u wildfly bash -c "/usr/local/bin/jstat -gccapacity -t $1"
fi
fi
}
function emptyJstatArray {
echo "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
}
function checkStats {
if [[ ${#JHSTAT[@]} < '16' ]] ; then JHSTAT=($(emptyJstatArray)); JHRUN=0 ; fi
if [[ ${#JPSTAT[@]} < '16' ]] ; then JPSTAT=($(emptyJstatArray)); JPRUN=0 ; fi
if [[ ${#JSTAT1[@]} < '16' ]] ; then JSTAT1=($(emptyJstatArray)); JS1RUN=0 ; fi
if [[ ${#JSTAT2[@]} < '16' ]] ; then JSTAT2=($(emptyJstatArray)); JS2RUN=0 ; fi
}
function getHostData {
TIMESTAMP=$(date +%s)
SENDING_DATA="\"$HOST\" jvm.hostcontroller.NGCMX $TIMESTAMP ${JHSTAT[2]}
\"$HOST\" jvm.hostcontroller.OGCMX $TIMESTAMP ${JHSTAT[8]}
\"$HOST\" jvm.hostcontroller.PGCMX $TIMESTAMP ${JHSTAT[12]}
\"$HOST\" jvm.hostcontroller.running $TIMESTAMP $JHRUN"
}
function getProcessData {
TIMESTAMP=$(date +%s)
SENDING_DATA="\"$HOST\" jvm.processcontroller.NGCMX $TIMESTAMP ${JPSTAT[2]}
\"$HOST\" jvm.processcontroller.OGCMX $TIMESTAMP ${JPSTAT[8]}
\"$HOST\" jvm.processcontroller.PGCMX $TIMESTAMP ${JPSTAT[12]}"
}
function getSlave100Data {
TIMESTAMP=$(date +%s)
SENDING_DATA="\"$HOST\" jvm.slave100.NGCMX $TIMESTAMP ${JSTAT1[2]}
\"$HOST\" jvm.slave100.OGCMX $TIMESTAMP ${JSTAT1[8]}
\"$HOST\" jvm.slave100.PGCMX $TIMESTAMP ${JSTAT1[12]}
\"$HOST\" jvm.slave100.running $TIMESTAMP $JS1RUN"
}
function getSlave200Data {
TIMESTAMP=$(date +%s)
SENDING_DATA="\"$HOST\" jvm.slave200.NGCMX $TIMESTAMP ${JSTAT2[2]}
\"$HOST\" jvm.slave200.OGCMX $TIMESTAMP ${JSTAT2[8]}
\"$HOST\" jvm.slave200.PGCMX $TIMESTAMP ${JSTAT2[12]}
\"$HOST\" jvm.slave200.running $TIMESTAMP $JS2RUN"
}
function sendStats {
if [[ $platform == 'sunos' ]] ; then
PREFIX='/opt/local/bin/'
else
PREFIX=""
fi
# zabbix_sender $ZS_PARAM -z service.theluckycatcasino.com -s "$(hostname)" -k "cluster.status" -o "$CLUSTER_STATUS" >> $TEMP_LOG_FILE
getProcessData
# echo "$SENDING_DATA"
result=$(echo "$SENDING_DATA" | ${PREFIX}zabbix_sender -c $ZABBIX_AGENTD_CONF -v -T -i - 2>&1)
# echo "$SENDING_DATA" >> $LOG
# echo "Result: $result" >> $LOG
getHostData
# echo "$SENDING_DATA"
result=$(echo "$SENDING_DATA" | ${PREFIX}zabbix_sender -c $ZABBIX_AGENTD_CONF -v -T -i - 2>&1)
getSlave100Data
# echo "$SENDING_DATA"
result=$(echo "$SENDING_DATA" | ${PREFIX}zabbix_sender -c $ZABBIX_AGENTD_CONF -v -T -i - 2>&1)
getSlave200Data
# echo "$SENDING_DATA"
result=$(echo "$SENDING_DATA" | ${PREFIX}zabbix_sender -c $ZABBIX_AGENTD_CONF -v -T -i - 2>&1)
}
function getStats {
#sudo -H -u wildfly bash -c '/usr/local/bin/jstat -gc -t 20674' && sudo -H -u wildfly bash -c '/usr/local/bin/jstat -gcutil -t 20674' && sudo -H -u wildfly bash -c "/usr/local/bin/jmap -heap 20674"
# Timestamp S0C S1C S0U S1U EC EU OC OU PC PU YGC YGCT FGC FGCT GCT
# 107737.6 8704.0 8704.0 2751.9 0.0 70208.0 32418.3 174784.0 29565.4 36288.0 36022.9 6 0.186 2 0.222 0.408
JHSTAT=($(getJstat $JHPID | grep -v "Timestamp"))
JPSTAT=($(getJstat $JPPID | grep -v "Timestamp"))
if [[ -n "$JSPID1" ]] ; then
JSTAT1=($(getJstat $JSPID1 | grep -v "Timestamp"))
JSTAT2=($(getJstat $JSPID2 | grep -v "Timestamp"))
fi
checkStats
sendStats
}
function checkRunning {
if [[ -n "$JHPID" ]] ; then
if ps -p $JHPID > /dev/null 2>&1
then
getStats
else
if [ "$FIRST" = true ]
then
FIRST=false
/opt/jvm-monitor/./create-pid-files.sh
getPids
checkRunning
else
exit 1
fi
fi
fi
}
. /opt/jvm-monitor/./get-platform.sh
if [[ $platform == 'sunos' ]] ; then
ZABBIX_AGENTD_CONF="/opt/local/etc/zabbix_agentd.conf"
fi
if [[ -n "$1" ]] ; then
ZABBIX_AGENTD_CONF=$1
fi
getPids
checkRunning
echo $JPRUN