Projet

Général

Profil

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

root / plugins / jvm / jvm_sun_minorgcs @ 17f78427

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

1
#!/usr/bin/perl -w
2

    
3
# Sun JVM minor GC statistics.  Parses a verbose log of minor GC
4
# stats.  Reads the log file and sums time in seconds spent on GC and
5
# number of times it is performed.  These numbers are saved in a state
6
# file. The next time the plugin is run it only reads from the point
7
# it quit the last time and increases the sums based on the lines
8
# found in the last portion of the log.  Thus we obtain counters.  The
9
# counters are reset when the log is rotated.
10

    
11
# The two numbers are graphed in _one_ graph.  Where it has been used
12
# until now these two numbers have been in the same order of
13
# magnitude.
14

    
15
# Configuration (common with the other sun_jvm_* plugins in this family):
16
# [jvm_sun_*]
17
#    env.logfile /var/foo/java.log  (default: /var/log/munin/java.log)
18
#    env.graphtitle                 (default: "Sun Java")
19
#    env.grname                     (default: "sun-jvm". Used for state file-name)
20

    
21
# You need to configure your Sun JVM with these options:
22
# -verbose:gc
23
# -Xloggc:/var/log/app/jvm/gc.log
24
# -XX:+PrintGCTimeStamps
25
# -XX:+PrintGCDetails
26

    
27
# History:
28

    
29
# This plugin was developed by various people over some time - no logs
30
# of this has been found. - In 2006 significant contributions was
31
# financed by NRK (Norwegian Broadcasting Coproration) and performed
32
# by Nicolai Langfeldt of Linpro AS in Oslo, Norway.
33

    
34
# $Id: $
35

    
36
use strict;
37

    
38
my $logfile = $ENV{logfile} || "/var/log/app/jvm/gc.log";
39
my $grtitle = $ENV{graphtitle} || 'Sun Java';
40
my $grname  = $ENV{graphtitle} || 'sun-jvm';
41

    
42
my $statefile = "$ENV{MUNIN_PLUGSTATE}/plugin-java_sun_${grname}_minorgcs.state";
43
my $pos   = 0;
44
my $count = 0;
45
my $seconds = 0;
46
my $startsize;
47
my $timespent;
48
my $totaltimespent=0;
49

    
50
if ( $ARGV[0] and $ARGV[0] eq "config" ) {
51
    print "graph_title $grtitle minor GCs pr minute\n";
52
    print "graph_args --base 1000 -l 0 --rigid\n";
53
    print "graph_scale no\n";
54
    print "graph_category virtualization\n";
55
    print "graph_period minute\n";
56
    print "gcs.label Number of GCs\n";
57
    print "gcs.type DERIVE\n";
58
    print "gcs.min 0\n";
59
    print "time.label Seconds spent on GC\n";
60
    print "time.type DERIVE\n";
61
    print "time.min 0\n";
62
    exit 0;
63
}
64

    
65
if (-l $statefile) {
66
	die("$statefile is a symbolic link, refusing to touch it.");
67
}
68

    
69
if (! -f $logfile) {
70
    print "gcs.value U\n";
71
    print "time.value U\n";
72
    exit 0;
73
}
74

    
75
if (-f "$statefile") {
76
    open (IN, "$statefile") or exit 4;
77
    ($pos,$count,$timespent) = split(/:/,<IN>);
78
    close IN;
79
}
80

    
81
$startsize = (stat $logfile)[7];
82

    
83
if ($startsize < $pos) {
84
    # Log rotated
85
    $pos = 0;
86
}
87

    
88
($pos, $count, $timespent) = parseFile ($logfile, $pos, $count, $timespent);
89

    
90
print "gcs.value $count\n";
91
print "time.value ",int($timespent),"\n";
92

    
93
open (OUT, ">$statefile") or die "Could not open $statefile for reading: $!\n";
94
print OUT "$pos:$count:$timespent\n";
95
close OUT;
96

    
97
sub parseFile {
98
    my ($fname, $start, $count, $timespent) = @_;
99
    my @secs;
100

    
101
    open (LOGFILE, $fname) or die "Could not open $fname: $!\n";
102

    
103
    # Stat filehandle after open - avoids race with logrotater or
104
    # restart or whatever.
105

    
106
    my $stop = $startsize = (stat LOGFILE)[7];
107

    
108
    if ($startsize < $start) {
109
	# Log rotated
110
	$start = 0;
111
    }
112

    
113
    seek (LOGFILE, $start, 0) or
114
	die "Could not seek to $start in $fname: $!\n";
115

    
116
    while (tell (LOGFILE) < $stop) {
117
	my $line =<LOGFILE>;
118
	chomp ($line);
119

    
120
# Log format: 35.037: [GC 35.038: [DefNew: 166209K->11364K(174080K), 0.2106410 secs] 175274K->26037K(1721472K), 0.2107680 secs]
121
	if ($line =~ /\[GC.+ (\d+\.\d+) secs\]/) {
122
	    $count++;
123
	    $timespent += $1;
124
	}
125
    }
126
    close(LOGFILE);
127
    return($stop,$count,$timespent);
128
}
129

    
130
# vim:syntax=perl