Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / java / jstat__gctime @ ef960abc

Historique | Voir | Annoter | Télécharger (4,08 ko)

1 09b6b49a Kosuke Uchida
#!/bin/bash
2
#
3
# Plugin for monitor JVM activity - GC Time -
4
#
5
# Usage:
6
#
7
#       Symlink into /etc/munin/plugins/ and add the monitored
8
#	alias name like :
9
#
10
#       ln -s /usr/share/munin/plugins/jstat__gctime \
11
#	  /etc/munin/plugins/jstat_<jvm alias>_gctime
12
#       This should, however, be given through autoconf and suggest.
13
#
14
# Requirements:
15
#
16
#	You need to execute your Java program under jsvc provided by
17
#	  http://jakarta.apache.org/commons/daemon/
18
#	which enables you to run your Java program with specified
19
#	pid file with -pidfile option.
20
#       A Brief setup documentation is also available at
21
#         http://tomcat.apache.org/tomcat-5.5-doc/setup.html
22
#
23
# Target:
24
#
25
#	Target Java Virtual Machine to monitor are:
26
#	  Sun JDK 5.0 (http://java.sun.com/javase/) (default)
27
#	  BEA JRockit 5.0 (http://dev2dev.bea.com/jrockit/)
28
#
29
# Parameters:
30
#
31
#       config   (required)
32
#
33
# Config variables:
34
#
35
#       pidfilepath  - Which file path use. Defaults to '/var/run/jsvc.pid'
36
#       javahome     - Defaults to '/usr/local/java/jdk'
37
#
38
DefaultPidFile="/var/run/jsvc.pid"
39
DefaultJavaHome="/usr/local/java/jdk"
40
41
#
42
# Environment Variables
43
#
44
if [ -z "${pidfilepath}" ]; then
45
  pidfilepath="${DefaultPidFile}"
46
fi
47
48
if [ -z "${graphtitle}" ]; then
49
  graphtitle="${pidfilepath}"
50
fi
51
52
if [ -z "${javahome}" ]; then
53
  JAVA_HOME="${DefaultJavaHome}"
54
else
55
  JAVA_HOME="${javahome}"
56
fi
57
export JAVA_HOME
58
59
#
60
# Functions
61
#
62
chk_jdk()
63
{
64
  isJRockit=`${JAVA_HOME}/bin/java -version 2>&1 | egrep -i 'jrockit'`
65
  if [ -n "${isJRockit}" ]; then
66
    JDK_TYPE="bea"
67
  else
68
    JDK_TYPE="sun"
69
  fi
70
}
71
72
chk_version()
73
{
74
  Version=`${JAVA_HOME}/bin/java -version 2>&1 | egrep '^java version' | awk '{print $3}' | sed -e 's/\"//g' | cut -d'_' -f 1`
75
  if [ "${Version}" != "1.5.0" ]; then
76
    return 1
77
  else
78
    return 0
79
  fi
80
}
81
82
config_common()
83
{
84
        echo 'graph_title GC Time' $graphtitle
85
        echo 'graph_args -l 0'
86
        echo 'graph_vlabel GC Time(sec)'
87
        echo 'graph_total total'
88
        echo 'graph_info GC Time'
89
        echo 'graph_category JVM'
90
}
91
92
config_sun_jdk()
93
{
94
  config_common
95
96
  echo 'Young_GC.label Young_GC'
97
  echo 'Young_GC.min 0'
98
  echo 'Full_GC.label Full_GC'
99
  echo 'Full_GC.min 0'
100
101
}
102
103
config_bea_jdk()
104
{
105
  config_common
106
107
  echo 'Young_GC.label Young_GC'
108
  echo 'Young_GC.min 0'
109
  echo 'Old_GC.label Old_GC'
110
  echo 'Old_GC.min 0'
111
  echo 'Young_Pause.label Young_GC Pause'
112
  echo 'Young_Pause.min 0'
113
  echo 'Old_Pause.label Old_GC Pause'
114
  echo 'Old_Pause.min 0'
115
  
116
}
117
118
print_sun_stats()
119
{
120
${JAVA_HOME}/bin/jstat -gc ${PidNum} | tail -1 | awk \
121
'{\
122
	S0C = $1; \
123
	S1C = $2; \
124
	S0U = $3; \
125
	S1U = $4; \
126
	EC  = $5; \
127
	EU  = $6; \
128
	OC  = $7; \
129
	OU  = $8; 
130
	PC  = $9; \
131
	PU  = $10; \
132
        YGC  = $11; \
133
        YGCT  = $12; \
134
        FGC  = $13; \
135
        FGCT  = $14; \
136
        GCT  = $15; \
137
138
	\
139
	S0F = S0C - S0U; \
140
	S1F = S1C - S1U; \
141
	EF  = EC  - EU;  \
142
	OF  = OC  - OU;  \
143
	PF  = PC  - PU;  \
144
	\
145
        print "Young_GC.value " YGCT; \
146
        print "Full_GC.value " FGCT; \
147
}'
148
}
149
150
print_bea_stats()
151
{
152
${JAVA_HOME}/bin/jstat -gc ${PidNum} | tail -1 | awk \
153
'{\
154
	HeapSize = $1; \
155
	NurserySize = $2; \
156
	UsedHeapSize = $3; \
157
	YC = $4; \
158
	OC = $5; \
159
	YCTime = $6; \
160
	OCTime = $7; \
161
	GCTime = $8; \
162
	YCPauseTime = $9; \
163
	OCPauseTime = $10; \
164
	PauseTime = $11; \
165
	Finalizers = $12; \
166
	\
167
	print "Young_GC.value " YCTime; \
168
	print "Old_GC.value " OCTime; \
169
	print "Young_Pause.value " YCPauseTime; \
170
	print "Old_Pause.value " OCPauseTime
171
}'
172
}
173
174
#
175
# common for all argument
176
#
177
chk_jdk
178
179
#
180
# autoconf
181
#
182
if [ "$1" = "autoconf" ]; then
183
184
  if [ ! -x "${JAVA_HOME}/bin/jstat" ]; then
185
    echo "no (No jstat found in ${JAVA_HOME}/bin)"
186
    exit 1
187
  fi
188
189
  chk_version
190
  if [ $? != 0 ]; then
191
    echo "no (Java version is invalid)"
192
    exit 1
193
  fi
194
195
  if [ ! -f "${pidfilepath}" -o ! -r "${pidfilepath}" ]; then
196
    echo "no (No such file ${pidfilepath} or cannot read ${pidfilepath}"
197
    exit 1
198
  fi
199
200
  echo "yes"
201
  exit 0
202
fi
203
204
205
#
206
# config
207
#
208
if [ "$1" = "config" ]; then
209
  if [ "${JDK_TYPE}" == "bea" ]; then
210
    config_bea_jdk
211
  else
212
    config_sun_jdk
213
  fi
214
  exit 0
215
fi
216
217
#
218
# Main
219
#
220
PidNum=`cat ${pidfilepath}`
221
222
if [ "${JDK_TYPE}" == "bea" ]; then
223
  print_bea_stats
224
else
225
  print_sun_stats
226
fi