Projet

Général

Profil

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

root / plugins / jvm / jstat__heap @ 6af31ea3

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

1
#!/bin/bash
2
#
3
# Plugin for monitor JVM activity - Heap Usage -
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__heap \
11
#	  /etc/munin/plugins/jstat_<jvm alias>_heap
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

    
39
pidfilepath=${pidfilepath:-/var/run/jsvc.pid}
40
graphtitle=${graphtitle:-$pidfilepath}
41
JAVA_HOME=${javahome:-/usr/local/java/jdk}
42

    
43
export JAVA_HOME
44

    
45
#
46
# Functions
47
#
48
chk_jdk()
49
{
50
  isJRockit=`${JAVA_HOME}/bin/java -version 2>&1 | egrep -i 'jrockit'`
51
  if [ -n "${isJRockit}" ]; then
52
    JDK_TYPE="bea"
53
  else
54
    JDK_TYPE="sun"
55
  fi
56
}
57

    
58
chk_version()
59
{
60
  Version=`${JAVA_HOME}/bin/java -version 2>&1 | egrep '^java version' | awk '{print $3}' | sed -e 's/\"//g' | cut -d'_' -f 1`
61
  if [ "${Version}" != "1.5.0" ]; then
62
    return 1
63
  else
64
    return 0
65
  fi
66
}
67

    
68
config_common()
69
{
70
  echo "graph_title Heap Usage" $graphtitle
71
  echo "graph_args --base 1024 -l 0"
72
  echo "graph_vlabel Heap Usage(Bytes)"
73
  echo "graph_info Heap Usage"
74
  echo "graph_category virtualization"
75
}
76

    
77
config_sun_jdk()
78
{
79
  config_common
80

    
81
  echo "Eden_Used.label Eden_Used"
82
  echo "Eden_Free.label Eden_Free"
83
  echo "Survivor0_Used.label Survivor0_Used"
84
  echo "Survivor0_Free.label Survivor0_Free"
85
  echo "Survivor1_Used.label Survivor1_Used"
86
  echo "Survivor1_Free.label Survivor1_Free"
87
  echo "Old_Used.label Old_Used"
88
  echo "Old_Free.label Old_Free"
89
  echo "Permanent_Used.label Permanent_Used"
90
  echo "Permanent_Free.label Permanent_Free"
91
  echo "Eden_Used.draw AREA"
92
  echo "Eden_Free.draw STACK"
93
  echo "Survivor0_Used.draw STACK"
94
  echo "Survivor0_Free.draw STACK"
95
  echo "Survivor1_Used.draw STACK"
96
  echo "Survivor1_Free.draw STACK"
97
  echo "Old_Used.draw STACK"
98
  echo "Old_Free.draw STACK"
99
  echo "Permanent_Used.draw STACK"
100
  echo "Permanent_Free.draw STACK"
101
}
102

    
103
config_bea_jdk()
104
{
105
  config_common
106

    
107
  echo "NurserySize.label NurserySize"
108
  echo "HeapSize.label HeapSize"
109
  echo "UsedHeapSize.label UsedHeapSize"
110
  echo "NurserySize.draw AREA"
111
  echo "HeapSize.draw STACK"
112
  echo "UsedHeapSize.draw STACK"
113
}
114

    
115
print_sun_stats()
116
{
117
${JAVA_HOME}/bin/jstat -gc ${PidNum} | tail -1 | awk \
118
'{\
119
	S0C = $1; \
120
	S1C = $2; \
121
	S0U = $3; \
122
	S1U = $4; \
123
	EC  = $5; \
124
	EU  = $6; \
125
	OC  = $7; \
126
	OU  = $8; \
127
	PC  = $9; \
128
	PU  = $10; \
129
	\
130
	S0F = S0C - S0U; \
131
	S1F = S1C - S1U; \
132
	EF  = EC  - EU;  \
133
	OF  = OC  - OU;  \
134
	PF  = PC  - PU;  \
135
	\
136
	print "Eden_Used.value " EU * 1024; \
137
	print "Eden_Free.value " EF * 1024; \
138
	print "Survivor0_Used.value " S0U * 1024; \
139
	print "Survivor0_Free.value " S0F * 1024; \
140
	print "Survivor1_Used.value " S1U * 1024; \
141
	print "Survivor1_Free.value " S1F * 1024; \
142
	print "Old_Used.value " OU * 1024; \
143
	print "Old_Free.value " OF * 1024; \
144
	print "Permanent_Used.value " PU * 1024; \
145
	print "Permanent_Free.value " PF * 1024; \
146
}'
147
}
148

    
149
print_bea_stats()
150
{
151
${JAVA_HOME}/bin/jstat -gc ${PidNum} | tail -1 | awk \
152
'{\
153
	HeapSize = $1; \
154
	NurserySize = $2; \
155
	UsedHeapSize = $3; \
156
	YC = $4; \
157
	OC = $5; \
158
	YCTime = $6; \
159
	OCTime = $7; \
160
	GCTime = $8; \
161
	YCPauseTime = $9; \
162
	OCPauseTime = $10; \
163
	PauseTime = $11; \
164
	Finalizers = $12; \
165
	\
166
	print "NurserySize.value " NurserySize * 1024; \
167
	print "HeapSize.value " UsedHeapSize * 1024; \
168
	print "UsedHeapSize.value " UsedHeapSize * 1024; \
169
}'
170
}
171

    
172
#
173
# common for all argument
174
#
175
chk_jdk
176

    
177
#
178
# autoconf
179
#
180
if [ "$1" = "autoconf" ]; then
181

    
182
  if [ ! -x "${JAVA_HOME}/bin/jstat" ]; then
183
    echo "no (No jstat found in ${JAVA_HOME}/bin)"
184
    exit 1
185
  fi
186

    
187
  chk_version
188
  if [ $? != 0 ]; then
189
    echo "no (Java version is invalid)"
190
    exit 1
191
  fi
192

    
193
  if [ ! -f "${pidfilepath}" -o ! -r "${pidfilepath}" ]; then
194
    echo "no (No such file ${pidfilepath} or cannot read ${pidfilepath}"
195
    exit 1
196
  fi
197

    
198
  echo "yes"
199
  exit 0
200
fi
201

    
202

    
203
#
204
# config
205
#
206
if [ "$1" = "config" ]; then
207
  if [ "${JDK_TYPE}" == "bea" ]; then
208
    config_bea_jdk
209
  else
210
    config_sun_jdk
211
  fi
212
  exit 0
213
fi
214

    
215
#
216
# Main
217
#
218
PidNum=`cat ${pidfilepath}`
219

    
220
if [ "${JDK_TYPE}" == "bea" ]; then
221
  print_bea_stats
222
else
223
  print_sun_stats
224
fi