~ubuntu-branches/ubuntu/gutsy/munin/gutsy

« back to all changes in this revision

Viewing changes to node/node.d.linux/iostat_ios.in

  • Committer: Bazaar Package Importer
  • Author(s): Tore Anderson
  • Date: 2004-05-21 20:51:19 UTC
  • Revision ID: james.westby@ubuntu.com-20040521205119-oz8bllbjp9hs80ig
Tags: upstream-0+1.0.0pre5
ImportĀ upstreamĀ versionĀ 0+1.0.0pre5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
@@PERL@@
 
2
#
 
3
#
 
4
# Plugin for watching io-bound traffic (in blocks) on disks.
 
5
#
 
6
# Usage: Link or copy into /etc/lrrd/client.d/
 
7
#
 
8
# Parameters:
 
9
#
 
10
#       config   (required)
 
11
#       autoconf (optional - used by lrrd-config)
 
12
#
 
13
# Magic markers (optional - used by lrrd-config and some installation 
 
14
# scripts):
 
15
 
16
#%# family=contrib
 
17
 
 
18
use strict;
 
19
 
 
20
use IO::File;
 
21
 
 
22
use Storable qw(store retrieve);
 
23
use Data::Dumper;
 
24
 
 
25
# (c) 2004 - Per Andreas Buer
 
26
# GPL v2 Yadda yadda.
 
27
 
 
28
use constant STATEFILE => '@@STATEDIR@@/iostat-aw.state';
 
29
 
 
30
 
 
31
if ($ARGV[0] eq 'config') {
 
32
    print_config();
 
33
    exit;
 
34
}
 
35
 
 
36
 
 
37
my ($r, $old_r);
 
38
 
 
39
$r = get_ios();
 
40
 
 
41
 
 
42
($old_r) = get_state();
 
43
 
 
44
 
 
45
 
 
46
if ($old_r) {
 
47
    cmp_io($old_r, $r);
 
48
} else {
 
49
    print "No historic data present\n";
 
50
}
 
51
 
 
52
store_state( $r );
 
53
 
 
54
 
 
55
sub filter {
 
56
    my ($major, $minor, $tmpnam);
 
57
    return 0 if ($major ==   1); # RAM devices
 
58
    return 0 if ($major ==   9); # MD devices
 
59
    return 0 if ($major ==  58); # LVM devices
 
60
    return 0 if ($major == 254); # LVM2 devices
 
61
    return 0 if ($tmpnam =~ /part\d+$/);
 
62
    return 0 if ($tmpnam =~ /^\s*(?:sd|hd)[a-z]\d+\s*$/);
 
63
 
 
64
    return 1;
 
65
}
 
66
 
 
67
 
 
68
 
 
69
sub get_ios {
 
70
    my ($opt) = @_;
 
71
 
 
72
    my %R;
 
73
    my ($parts, $kernel);
 
74
    my @dev;
 
75
    
 
76
    if (-r "/proc/diskstats") {
 
77
        $kernel = 2.6;
 
78
        $parts = new IO::File("/proc/diskstats") || die();
 
79
    } else {
 
80
        $kernel = 2.4;
 
81
        $parts = new IO::File("/proc/partitions");
 
82
        die("kernel $kernel not supported yet\n");
 
83
    }
 
84
 
 
85
    unless ($parts) {
 
86
        print "Could not gather statistics\n";
 
87
        return undef;
 
88
    }
 
89
 
 
90
    while (<$parts>) {
 
91
         my ($maj, $min, $name, $rio, $rtime, $wio, $wtime);
 
92
 
 
93
         ($maj, $min, $name, 
 
94
          $rio, $rtime, $wio, $wtime) = 
 
95
           (split(/\s+/, $_ ))[1,2,3,4,7,8,11];
 
96
 
 
97
         next unless( defined($min) && defined($maj));
 
98
         next unless ($wio and $rio and $rtime and $wtime);
 
99
 
 
100
         next if ( filter($maj, $min, $name) == 0);
 
101
 
 
102
         $R{$maj}{$min}{rio}   =  $rio;
 
103
         $R{$maj}{$min}{rtime} =  $rtime;
 
104
 
 
105
         $R{$maj}{$min}{wio}   =  $wio;
 
106
         $R{$maj}{$min}{wtime} =  $wtime;
 
107
         push(@dev, "dev${maj}_${min}");
 
108
    }
 
109
    $parts->close();
 
110
 
 
111
    if ($opt) {
 
112
        return \@dev;
 
113
    } else {
 
114
        return \%R;
 
115
    }
 
116
}
 
117
 
 
118
sub print_config {
 
119
 
 
120
    print("graph_title IO Service time\n",
 
121
          "graph_args --base 1000\n",
 
122
          "graph_vlabel ms\n");
 
123
 
 
124
    for my $d ( @{ get_ios(1) } ) {
 
125
        print("$d.label $d\n",
 
126
              "$d.type GAUGE\n",
 
127
              "$d.draw LINE2\n");
 
128
    }
 
129
}
 
130
 
 
131
 
 
132
sub cmp_io {
 
133
    my ($old_io, $new_io) = @_;
 
134
    my %KEYS;
 
135
 
 
136
    for my $maj (sort keys %{$new_io} ) {
 
137
        for my $min (sort keys %{ $new_io->{$maj} } ) {
 
138
            my $rio_diff   = $$new_io{$maj}{$min}{rio}  - $$old_io{$maj}{$min}{rio};
 
139
            my $rtime_diff   = $$new_io{$maj}{$min}{rtime}  - $$old_io{$maj}{$min}{rtime};
 
140
            
 
141
 
 
142
            my $wio_diff   = $$new_io{$maj}{$min}{wio}  - $$old_io{$maj}{$min}{wio};
 
143
            my $wtime_diff   = $$new_io{$maj}{$min}{wtime}  - $$old_io{$maj}{$min}{wtime};
 
144
            
 
145
            my $dev = "dev${maj}_${min}";
 
146
 
 
147
            print("${dev}_rtime.value ", ($rtime_diff != 0) ? ($rio_diff / $rtime_diff) : 0, "\n",
 
148
                  "${dev}_wtime.value ", ($wtime_diff != 0) ? ($wio_diff / $wtime_diff) : 0, "\n",
 
149
                  );
 
150
        }
 
151
    }
 
152
 
 
153
}
 
154
 
 
155
sub store_state {
 
156
    my ($R) = @_;
 
157
    store($R, STATEFILE);
 
158
}
 
159
 
 
160
sub get_state {
 
161
    my ($R);
 
162
    return(undef) unless ( -r STATEFILE);
 
163
    $R = retrieve( STATEFILE );
 
164
    return($R);
 
165
}