Projet

Général

Profil

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

root / plugins / java / jstat__gccount @ e5ce7492

Historique | Voir | Annoter | Télécharger (3,95 ko)

1
#!/bin/bash
2
#
3
# Plugin for monitor JVM activity - GC Count -
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__gccount \
11
#	  /etc/munin/plugins/jstat_<jvm alias>_gccount
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 Count' $graphtitle
85
  echo 'graph_args -l 0'
86
  echo 'graph_vlabel GC Count(times)'
87
  echo 'graph_total total'
88
  echo 'graph_info GC Count'
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
}
112

    
113
print_sun_stats()
114
{
115
${JAVA_HOME}/bin/jstat -gc ${PidNum} | tail -1 | awk \
116
'{\
117
        S0C = $1; \
118
        S1C = $2; \
119
        S0U = $3; \
120
        S1U = $4; \
121
        EC  = $5; \
122
        EU  = $6; \
123
        OC  = $7; \
124
        OU  = $8; \
125
        PC  = $9; \
126
        PU  = $10; \
127
        YGC  = $11; \
128
        YGCT  = $12; \
129
        FGC  = $13; \
130
        FGCT  = $14; \
131
        GCT  = $15; \
132
        \
133
        S0F = S0C - S0U; \
134
        S1F = S1C - S1U; \
135
        EF  = EC  - EU;  \
136
        OF  = OC  - OU;  \
137
        PF  = PC  - PU;  \
138
        \
139
        print "Young_GC.value " YGC; \
140
        print "Full_GC.value " FGC; \
141
}'
142
}
143

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

    
166
#
167
# common for all argument
168
#
169
chk_jdk
170

    
171
#
172
# autoconf
173
#
174
if [ "$1" = "autoconf" ]; then
175

    
176
  if [ ! -x "${JAVA_HOME}/bin/jstat" ]; then
177
    echo "no (No jstat found in ${JAVA_HOME}/bin)"
178
    exit 1
179
  fi
180

    
181
  chk_version
182
  if [ $? != 0 ]; then
183
    echo "no (Java version is invalid)"
184
    exit 1
185
  fi
186

    
187
  if [ ! -f "${pidfilepath}" -o ! -r "${pidfilepath}" ]; then
188
    echo "no (No such file ${pidfilepath} or cannot read ${pidfilepath}"
189
    exit 1
190
  fi
191

    
192
  echo "yes"
193
  exit 0
194
fi
195

    
196

    
197
#
198
# config
199
#
200
if [ "$1" = "config" ]; then
201
  if [ "${JDK_TYPE}" == "bea" ]; then
202
    config_bea_jdk
203
  else
204
    config_sun_jdk
205
  fi
206
  exit 0
207
fi
208

    
209
#
210
# Main
211
#
212
PidNum=`cat ${pidfilepath}`
213

    
214
if [ "${JDK_TYPE}" == "bea" ]; then
215
  print_bea_stats
216
else
217
  print_sun_stats
218
fi