Projet

Général

Profil

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

root / plugins / jvm / jstat__gccount @ 6af31ea3

Historique | Voir | Annoter | Télécharger (3,76 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

    
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 GC Count' $graphtitle
71
  echo 'graph_args -l 0'
72
  echo 'graph_vlabel GC Count(times)'
73
  echo 'graph_total total'
74
  echo 'graph_info GC Count'
75
  echo 'graph_category virtualization'
76
}
77

    
78
config_sun_jdk()
79
{
80
  config_common
81

    
82
  echo 'Young_GC.label Young_GC'
83
  echo 'Young_GC.min 0'
84
  echo 'Full_GC.label Full_GC'
85
  echo 'Full_GC.min 0'
86

    
87
}
88

    
89
config_bea_jdk()
90
{
91
  config_common
92

    
93
  echo 'Young_GC.label Young_GC'
94
  echo 'Young_GC.min 0'
95
  echo 'Old_GC.label Old_GC'
96
  echo 'Old_GC.min 0'
97
}
98

    
99
print_sun_stats()
100
{
101
${JAVA_HOME}/bin/jstat -gc ${PidNum} | tail -1 | awk \
102
'{\
103
        S0C = $1; \
104
        S1C = $2; \
105
        S0U = $3; \
106
        S1U = $4; \
107
        EC  = $5; \
108
        EU  = $6; \
109
        OC  = $7; \
110
        OU  = $8; \
111
        PC  = $9; \
112
        PU  = $10; \
113
        YGC  = $11; \
114
        YGCT  = $12; \
115
        FGC  = $13; \
116
        FGCT  = $14; \
117
        GCT  = $15; \
118
        \
119
        S0F = S0C - S0U; \
120
        S1F = S1C - S1U; \
121
        EF  = EC  - EU;  \
122
        OF  = OC  - OU;  \
123
        PF  = PC  - PU;  \
124
        \
125
        print "Young_GC.value " YGC; \
126
        print "Full_GC.value " FGC; \
127
}'
128
}
129

    
130
print_bea_stats()
131
{
132
${JAVA_HOME}/bin/jstat -gc ${PidNum} | tail -1 | awk \
133
'{\
134
	HeapSize = $1; \
135
	NurserySize = $2; \
136
	UsedHeapSize = $3; \
137
	YC = $4; \
138
	OC = $5; \
139
	YCTime = $6; \
140
	OCTime = $7; \
141
	GCTime = $8; \
142
	YCPauseTime = $9; \
143
	OCPauseTime = $10; \
144
	PauseTime = $11; \
145
	Finalizers = $12; \
146
	\
147
	print "Young_GC.value " YC; \
148
	print "Old_GC.value " OC;\
149
}'
150
}
151

    
152
#
153
# common for all argument
154
#
155
chk_jdk
156

    
157
#
158
# autoconf
159
#
160
if [ "$1" = "autoconf" ]; then
161

    
162
  if [ ! -x "${JAVA_HOME}/bin/jstat" ]; then
163
    echo "no (No jstat found in ${JAVA_HOME}/bin)"
164
    exit 1
165
  fi
166

    
167
  chk_version
168
  if [ $? != 0 ]; then
169
    echo "no (Java version is invalid)"
170
    exit 1
171
  fi
172

    
173
  if [ ! -f "${pidfilepath}" -o ! -r "${pidfilepath}" ]; then
174
    echo "no (No such file ${pidfilepath} or cannot read ${pidfilepath}"
175
    exit 1
176
  fi
177

    
178
  echo "yes"
179
  exit 0
180
fi
181

    
182

    
183
#
184
# config
185
#
186
if [ "$1" = "config" ]; then
187
  if [ "${JDK_TYPE}" == "bea" ]; then
188
    config_bea_jdk
189
  else
190
    config_sun_jdk
191
  fi
192
  exit 0
193
fi
194

    
195
#
196
# Main
197
#
198
PidNum=`cat ${pidfilepath}`
199

    
200
if [ "${JDK_TYPE}" == "bea" ]; then
201
  print_bea_stats
202
else
203
  print_sun_stats
204
fi