Projet

Général

Profil

Révision f0548a37

IDf0548a37defad384b6a23844111edbeee8ea2b6d
Parent 7c397d94
Enfant 4e713c9b

Ajouté par Stefan Huehner il y a presque 7 ans

Fix jstat* plugins to work again with java 6+7, fix PU reporting for
Java8.

jstat column output is not stable across JVM versions (technically
version of jstat binary used).
New columns are added not add the end of column list but in the middle
breaking access via constant index.

Following table shows the known columns per version:
Oracle JDK / OpenJDK 1.5 .. 1.7
S0C S1C S0U S1U EC EU OC OU PC PU YGC YGCT FGC FGCT GCT
Openjdk 1.8 .. 10
S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
Openjdk 11 .. 12
S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT CGC CGCT GCT

Earlier commit here added support for java8+ but using version checking
if version == 1.5 > Use pre-java8 column format, else new format.

As fixing java6+7 would mean more version comparison which is ugly this
cmomit changes retrival logic to the following;
a.) Parse first line jstat output to find position for each label
b.) Then use that position to fetch value from 2nd line

That way code auto-adjusts to any ordering change without needing any
java version specific code or checks.

On the way fix 'Permanent Used' value reporting for java8 which was
broken (missing variable rename from PU -> MU when java8 support was
added).

Voir les différences:

plugins/jvm/jstat__gccount
25 25
#       Target Java Virtual Machine to monitor are:
26 26
#         Sun JDK 5.0 (http://java.sun.com/javase/)
27 27
#         Sun JDK 8.0 (http://java.sun.com/javase/)
28
#         OpenJDK 1.7 .. 11 (https://openjdk.java.net/)
28 29
#         BEA JRockit 5.0 (http://dev2dev.bea.com/jrockit/)
29 30
#
30 31
# Parameters:
......
53 54
    if "${JAVA_HOME}/bin/java" -version 2>&1 | grep -qi 'jrockit'; then
54 55
        echo "bea"
55 56
    else
56
        version=$("${JAVA_HOME}/bin/java" -version 2>&1 | grep '^java version' | awk '{print $3}' | sed -e 's/\"//g' | cut -d'_' -f 1)
57
        if echo "$version" | grep -q '^1\.5\.'; then
58
            echo "sun15"
59
        else
60
            echo "sun"
61
        fi
57
        echo "sun"
62 58
  fi
63 59
}
64 60

  
......
89 85
    if [ "${JDK_TYPE}" = "bea" ]; then
90 86
        # shellcheck disable=SC2016
91 87
        awk_script='{ YC = $4; OC = $5; print "Young_GC.value " YGC; print "Old_GC.value " FGC; }'
92
    elif [ "${JDK_TYPE}" = "sun15" ]; then
93
        # shellcheck disable=SC2016
94
        awk_script='{ YGC = $11; FGC = $13; print "Young_GC.value " YGC; print "Full_GC.value " FGC; }'
95 88
    else
96
        # example output of jstat for Java 1.8:
97
        #   S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
98
        #   2048.0 2048.0 0.0 1344.0 694784.0 145013.5 1398272.0 414857.1 102400.0 96308.0 12544.0 11240.1 979 20.997 5 2.705 23.702
89
        # List & Order of columns of jstat changes with java versions
90
        # idx["YGC"] is index of YGC column in output (i.e. 13)
91
        # $idx["YGC"] then accesses the value at this position (taken from 2nd line of the output)
99 92
        # shellcheck disable=SC2016
100
        awk_script='{ YGC = $13; FGC = $15; print "Young_GC.value " YGC; print "Full_GC.value " FGC; }'
93
        awk_script='
94
            NR==1 { 
95
                for (i=1;i<=NF;i++) idx[$i]=i
96
            }
97
            NR==2 {
98
                print "Young_GC.value " $idx["YGC"];
99
                print "Full_GC.value " $idx["FGC"];
100
            }'
101 101
    fi
102
    "${JAVA_HOME}/bin/jstat" -gc "$pid_num" | tail -1 | awk "$awk_script"
102
    "${JAVA_HOME}/bin/jstat" -gc "$pid_num" | awk "$awk_script"
103 103
}
104 104

  
105 105

  

Formats disponibles : Unified diff