summaryrefslogtreecommitdiff
path: root/files/plugins/xen_vbd
blob: e34d41c86a53681ea4ed74cae694a9144c662ec9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/perl
#
# 2007-06-01    Zoltan HERPAI <wigyori@uid0.hu>
#
# Credits goes for:
# Adam Crews for his xen_cpu plugin
# Mario Manno for his xen_traffic_all plugin
#
# Script to monitor the I/O usage of Xen domains
# Version 0.1
#
#%# family=auto
#%# capabilities=autoconf

# Location of xm tools
$XM = '/usr/sbin/xm';
$XMTOP = '/usr/sbin/xentop';

# we cache xm list for 5 min for perfomance reasons
system('((find /var/lib/munin/plugin-state/xm_list.state -mmin -5 2>&1 | grep -qE \'^\/var\/lib\/munin\/plugin-state\/xm_list\.state$\') && [ `cat /var/lib/munin/plugin-state/xm_list.state | wc -l` -gt 1 ]) || /usr/sbin/xm list | grep -v "^Name .* ID" > /var/lib/munin/plugin-state/xm_list.state');
system('((find /var/lib/munin/plugin-state/xm_top.state -mmin -5 2>&1 | grep -qE \'^\/var\/lib\/munin\/plugin-state\/xm_top\.state$\') && [ `cat /var/lib/munin/plugin-state/xm_top.state | wc -l` -gt 1 ]) || /usr/sbin/xentop -b -i1 | grep -E "^ " > /var/lib/munin/plugin-state/xm_top.state');

# ah, parameters coming in
if ( defined($ARGV[0]))
{
        if ($ARGV[0] eq 'config') { $arg = 'config'; }
        if ($ARGV[0] eq 'autoconf') { $arg = 'autoconf'; }

        if ( $arg eq 'autoconf' )
        {
                if ( -e $XM && -e $XMTOP )
                {
                        print "yes\n";
                        exit 0;
                }
                else
                {
                        print "no ($XM and/or $XMTOP not found\n";
                        exit 0;
                }
        }

        if ( $arg eq 'config' )
        {
                %cnf = (
                        'graph_title' => 'Xen Domain I/O usage',
                        'graph_args' => '--base 1024 -l 0',
                        'graph_vlabel' => 'read (-), write (+)',
                        'graph_category' => 'xen',
                        'graph_info' => 'Display the I/O operations for each domain',
                );

                @domains = `cat /var/lib/munin/plugin-state/xm_list.state | grep -v 'Domain-0'`;

                foreach $domain ( @domains )
                {
                        ($dom, undef) = split(/\s/, $domain);
                        $dom =~ s/[-.]/_/g;

                        $cnf{ $dom.'RD' . '.label' } = 'read';
                        $cnf{ $dom.'RD' . '.type' } = 'COUNTER';
                        $cnf{ $dom.'RD' . '.graph' } = 'no';
                        $cnf{ $dom.'RD' . '.cdef' } = $dom.'RD,8,*';

                        $cnf{ $dom.'WR' . '.label' } = $dom;
                        $cnf{ $dom.'WR' . '.type' } = 'COUNTER';
                        $cnf{ $dom.'WR' . '.negative' } = $dom.'RD';
                        $cnf{ $dom.'WR' . '.cdef' } = $dom.'WR,8,*';

                        if ( "$cnt" == "0" )
                        {
                                $cnf { "$dom" . '.draw' } = 'AREA';
                        }
                        $cnt++;
                }

                foreach $key ( sort(keys(%cnf)) )
                {
                        print "$key $cnf{$key}\n";
                }
                exit 0;

        }
}


# No args, get rolling
my @stats = `cat /var/lib/munin/plugin-state/xm_top.state | grep -v 'Domain-0'`;

# remove the first line
shift(@stats);

my %vals; undef(%vals);

foreach my $domain (@stats) {
	# trim the leading whitespace
        $domain =~ s/^\s+//;
        my @tmp = split(/\s+/, $domain);

        # we need to change - and . to _ or things get weird with the graphs
        # some decent quoting would probably fix this, but this works for now
        $tmp[0] =~ s/[-.]/_/g;

        $domname = $tmp[0];
        $domname =~ s/[-.]/_/g;
        $vbdrd = $tmp[14];
        $vbdwr = $tmp[15];

        $vals{$domname."RD"}{'value'} = $vbdrd;
        $vals{$domname."WR"}{'value'} = $vbdwr;
}

foreach $key ( sort(keys(%vals)) )
{
        print "$key.value " . ($vals{$key}{'value'}) . "\n";
}