Projet

Général

Profil

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

root / plugins / jvm / jstat__heap @ f0548a37

Historique | Voir | Annoter | Télécharger (5,11 ko)

1 67f97837 Lars Kruse
#!/bin/sh
2 9d4c6ab7 Kosuke Uchida
#
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 f5e6d7ea Lars Kruse
#       Target Java Virtual Machine to monitor are:
26
#         Sun JDK 5.0 (http://java.sun.com/javase/)
27
#         Sun JDK 8.0 (http://java.sun.com/javase/)
28 f0548a37 Stefan Huehner
#         OpenJDK 1.7 .. 11 (https://openjdk.java.net/)
29 f5e6d7ea Lars Kruse
#         BEA JRockit 5.0 (http://dev2dev.bea.com/jrockit/)
30 9d4c6ab7 Kosuke Uchida
#
31
# Parameters:
32
#
33
#       config   (required)
34
#
35
# Config variables:
36
#
37
#       pidfilepath  - Which file path use. Defaults to '/var/run/jsvc.pid'
38 7a52b375 Lars Kruse
#       javahome     - override automatic detection of JRE directory
39 4c755fd4 Lars Kruse
#       graphtitle   - Title of the graph (defaults to PID file location)
40 9d4c6ab7 Kosuke Uchida
#
41
42 7a52b375 Lars Kruse
default_java_home=/usr/lib/jvm/default-java
43
[ -e "$default_java_home" ] || default_java_home=/usr/local/java/jdk
44
45 6af31ea3 Lars Kruse
pidfilepath=${pidfilepath:-/var/run/jsvc.pid}
46
graphtitle=${graphtitle:-$pidfilepath}
47 7a52b375 Lars Kruse
JAVA_HOME=${javahome:-$default_java_home}
48 9d4c6ab7 Kosuke Uchida
49
export JAVA_HOME
50
51
52 f5e6d7ea Lars Kruse
get_jdk_type() {
53
    local version
54
    if "${JAVA_HOME}/bin/java" -version 2>&1 | grep -qi 'jrockit'; then
55
        echo "bea"
56
    else
57 f0548a37 Stefan Huehner
        echo "sun"
58 9d4c6ab7 Kosuke Uchida
  fi
59
}
60
61 f5e6d7ea Lars Kruse
62 3398ff3c Lars Kruse
print_config() {
63 67f97837 Lars Kruse
    echo "graph_title Heap Usage $graphtitle"
64 3398ff3c Lars Kruse
    echo "graph_args --base 1024 -l 0"
65
    echo "graph_vlabel Heap Usage(Bytes)"
66
    echo "graph_info Heap Usage"
67
    echo "graph_category virtualization"
68
69 67f97837 Lars Kruse
    if [ "${JDK_TYPE}" = "bea" ]; then
70 3398ff3c Lars Kruse
        echo "NurserySize.label NurserySize"
71
        echo "HeapSize.label HeapSize"
72
        echo "UsedHeapSize.label UsedHeapSize"
73
        echo "NurserySize.draw AREA"
74
        echo "HeapSize.draw STACK"
75
        echo "UsedHeapSize.draw STACK"
76
    else
77
        echo "Eden_Used.label Eden_Used"
78
        echo "Eden_Free.label Eden_Free"
79
        echo "Survivor0_Used.label Survivor0_Used"
80
        echo "Survivor0_Free.label Survivor0_Free"
81
        echo "Survivor1_Used.label Survivor1_Used"
82
        echo "Survivor1_Free.label Survivor1_Free"
83
        echo "Old_Used.label Old_Used"
84
        echo "Old_Free.label Old_Free"
85
        echo "Permanent_Used.label Permanent_Used"
86
        echo "Permanent_Free.label Permanent_Free"
87
        echo "Eden_Used.draw AREA"
88
        echo "Eden_Free.draw STACK"
89
        echo "Survivor0_Used.draw STACK"
90
        echo "Survivor0_Free.draw STACK"
91
        echo "Survivor1_Used.draw STACK"
92
        echo "Survivor1_Free.draw STACK"
93
        echo "Old_Used.draw STACK"
94
        echo "Old_Free.draw STACK"
95
        echo "Permanent_Used.draw STACK"
96
        echo "Permanent_Free.draw STACK"
97
    fi
98 9d4c6ab7 Kosuke Uchida
}
99
100
101 3398ff3c Lars Kruse
print_stats() {
102
    local pid_num="$1"
103
    local awk_script
104 67f97837 Lars Kruse
    if [ "${JDK_TYPE}" = "bea" ]; then
105 3398ff3c Lars Kruse
        # shellcheck disable=SC2016
106
        awk_script='{
107
            HeapSize = $1;
108
            NurserySize = $2;
109
            UsedHeapSize = $3;
110
            print "NurserySize.value " NurserySize * 1024;
111
            print "HeapSize.value " HeapSize * 1024;
112
            print "UsedHeapSize.value " UsedHeapSize * 1024; }'
113 f5e6d7ea Lars Kruse
    else
114 f0548a37 Stefan Huehner
        # List & Order of columns of jstat changes with java versions
115
        # idx["YGC"] is index of YGC column in output (i.e. 13)
116
        # $idx["YGC"] then accesses the value at this position (taken from 2nd line of the output)
117 f5e6d7ea Lars Kruse
        # shellcheck disable=SC2016
118 f0548a37 Stefan Huehner
        awk_script='
119
	    NR==1 { 
120
                for (i=1;i<=NF;i++) idx[$i]=i
121
            }
122
            NR==2 {
123
                S0F = $idx["S0C"] - $idx["S0U"];
124
                S1F = $idx["S1C"] - $idx["S1U"];
125
                EF  = $idx["EC"]  - $idx["EU"];
126
                OF  = $idx["OC"]  - $idx["OU"];
127
                MF  = $idx["MC"]  - $idx["MU"];
128
                print "Eden_Used.value " $idx["EU"] * 1024;
129
                print "Eden_Free.value " EF * 1024;
130
                print "Survivor0_Used.value " $idx["S0U"] * 1024;
131
                print "Survivor0_Free.value " S0F * 1024;
132
                print "Survivor1_Used.value " $idx["S1U"] * 1024;
133
                print "Survivor1_Free.value " S1F * 1024;
134
                print "Old_Used.value " $idx["OU"] * 1024;
135
                print "Old_Free.value " OF * 1024;
136
                print "Permanent_Used.value " $idx["MU"] * 1024;
137
                print "Permanent_Free.value " MF * 1024;
138
            }'
139 3398ff3c Lars Kruse
    fi
140 f0548a37 Stefan Huehner
    "${JAVA_HOME}/bin/jstat" -gc "$pid_num" | awk "$awk_script"
141 9d4c6ab7 Kosuke Uchida
}
142
143
144
#
145
# autoconf
146
#
147
if [ "$1" = "autoconf" ]; then
148
149
  if [ ! -x "${JAVA_HOME}/bin/jstat" ]; then
150
    echo "no (No jstat found in ${JAVA_HOME}/bin)"
151 9cef55a3 Lars Kruse
  elif [ ! -f "$pidfilepath" ]; then
152
    echo "no (missing file $pidfilepath)"
153
  elif [ ! -r "$pidfilepath" ]; then
154
    echo "no (cannot read $pidfilepath)"
155
  else
156
    echo "yes"
157 9d4c6ab7 Kosuke Uchida
  fi
158
  exit 0
159
fi
160
161
162 f5e6d7ea Lars Kruse
JDK_TYPE=$(get_jdk_type)
163
164
165 9d4c6ab7 Kosuke Uchida
if [ "$1" = "config" ]; then
166 3398ff3c Lars Kruse
    print_config
167 9d4c6ab7 Kosuke Uchida
fi
168
169 3398ff3c Lars Kruse
print_stats "$(cat "$pidfilepath")"