summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 37f624d)
raw | patch | inline | side by side (parent: 37f624d)
author | Chris Lundquist <chris.lundquist@bluebox.net> | |
Wed, 27 Feb 2013 23:57:36 +0000 (15:57 -0800) | ||
committer | Chris Lundquist <chris.lundquist@bluebox.net> | |
Wed, 27 Feb 2013 23:57:36 +0000 (15:57 -0800) |
bindings/perl/lib/Collectd/Plugins/OpenVZ.pm | patch | blob | history |
diff --git a/bindings/perl/lib/Collectd/Plugins/OpenVZ.pm b/bindings/perl/lib/Collectd/Plugins/OpenVZ.pm
index 2e011b1f4f11524a8f1637d548be5779b6ff0c3b..cdb5dd777dc9452f28ef90bb9179ad1fcc22226d 100644 (file)
use strict;
use warnings;
-#use Collectd qw( :all );
+use Collectd qw( :all );
my $vzctl = '/usr/sbin/vzctl';
my $vzlist = '/usr/sbin/vzlist';
sub interface_read($$) {
my $veid = shift;
my $name = shift;
- my ($current_interface, $val, @lines, @parts, @counters, $i);
+ my ($val, @lines, @parts, @counters, $i);
my @if_instances = ('if_octets', 'if_packets', 'if_errors');
+ my @rx_fields = qw(if_octets if_packets if_errors drop fifo frame compressed multicast);
+ my @tx_fields = qw(if_octets if_packets if_errors drop fifo frame compressed);
my %v = _build_report_hash($name);
$v{'plugin'} = 'interface';
# face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
# lo: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
# venet0: 2420 27 0 0 0 0 0 0 2200 29 0 0 0 0 0 0
- foreach (@lines) {
- next if (!/:/);
+ #
+
+ for my $line (@lines) {
+ next if $line !~ /:/;
+
+ $line =~ s/^\s+|\s+$//g;
- @parts = split(/:/);
- ($current_interface = $parts[0]) =~ s/^\s*(.*?)\s*$/$1/;
- next if grep { $current_interface eq $_ } @ignored_interfaces;
+ my ($iface, %rx, %tx);
- ($val = $parts[1]) =~ s/^\s*(.*?)\s*$/$1/;
- @counters = split(/ +/, $val);
+ # Build our hash data
+ ($iface, @rx{@rx_fields}, @tx{@tx_fields}) = split /[: ]+/, $line;
- $v{'plugin_instance'} = $current_interface;
- for ($i= 0; $i <= $#if_instances; ++$i) {
- $v{'type'} = $if_instances[$i];
- $v{'values'} = [ $counters[$i], $counters[$i + 8] ];
+ # Skip this interface if it is in the ignored list
+ next if grep { $iface eq $_ } @ignored_interfaces;
+
+ $v{'plugin_instance'} = $iface;
+ for my $instance (@if_instances) {
+ $v{'type'} = $instance;
+ $v{'values'} = [ $rx{$instance}, $tx{$instance} ];
plugin_dispatch_values(\%v);
+ }
}
}
-}
sub cpu_read($$) {
my $veid = shift;