summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: da6abb2)
raw | patch | inline | side by side (parent: da6abb2)
author | Josh Yotty <jyotty@bluebox.net> | |
Thu, 28 Feb 2013 00:34:41 +0000 (16:34 -0800) | ||
committer | Josh Yotty <jyotty@bluebox.net> | |
Thu, 28 Feb 2013 00:34:41 +0000 (16:34 -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 cdb5dd777dc9452f28ef90bb9179ad1fcc22226d..68d81ba48cadd8c84ce23c1b39f3783b37b6018e 100644 (file)
# We probably don't care about loopback transfer
my @ignored_interfaces = ( "lo" );
-sub interface_read($$) {
- my $veid = shift;
- my $name = shift;
- my ($val, @lines, @parts, @counters, $i);
- my @if_instances = ('if_octets', 'if_packets', 'if_errors');
+sub interface_read {
+ my ($veid, $name) = @_
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);
+ my $v = _build_report_hash($name);
- $v{'plugin'} = 'interface';
- delete $v{'plugin_instance'};
+ $v->{'plugin'} = 'interface';
+ delete $v->{'plugin_instance'};
- @lines = split(/\n/, `$vzctl exec $veid cat /proc/net/dev`);
- #$ vzctl exec 1106221 cat /proc/net/dev
- #Inter-| Receive | Transmit
- # 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
- #
+ my @lines = `$vzctl exec $veid cat /proc/net/dev`;
for my $line (@lines) {
+ # skip explanatory text
next if $line !~ /:/;
$line =~ s/^\s+|\s+$//g;
my ($iface, %rx, %tx);
- # Build our hash data
+ # read /proc/net/dev fields
($iface, @rx{@rx_fields}, @tx{@tx_fields}) = split /[: ]+/, $line;
# 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);
+ $v->{'plugin_instance'} = $iface;
+ for my $instance (qw(if_octets if_packets if_errors)) {
+ $v->{'type'} = $instance;
+ $v->{'values'} = [ $rx{$instance}, $tx{$instance} ];
+ plugin_dispatch_values($v);
}
}
}
-sub cpu_read($$) {
+sub cpu_read {
my $veid = shift;
my $name = shift;
my ($key, $val, $i, @lines, @counters);
}
}
-sub df_read($$) {
+sub df_read {
my $veid = shift;
my $name = shift;
my ($key, $val, @lines, @parts);
}
}
-sub load_read($$) {
+sub load_read {
my $veid = shift;
my $name = shift;
my ($key, $val, @lines, @parts);
plugin_dispatch_values(\%v);
}
-sub processes_read($$) {
+sub processes_read {
my $veid = shift;
my $name = shift;
my ($key, $val, @lines);
}
}
-sub users_read($$) {
+sub users_read {
my $veid = shift;
my $name = shift;
my ($key, $val, @lines);
plugin_dispatch_values(\%v);
}
-sub _build_report_hash($) {
+sub _build_report_hash {
my $name = shift;
return (time => time(), interval => plugin_get_interval(), host => $name);
}