blib/lib/MYDan/Collector/Stat/IFace.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 52 CC 4 SCAR 17.0
CC
4
Cov
0%
co
12.0
BEGIN
6.0
BEGIN
2.0
CRAP 5.5
1 package MYDan::Collector::Stat::IFace;
2  
3 use strict;
4 use warnings;
5 use Carp;
6 use POSIX;
7  
8 use Data::Dumper;
9 use MYDan::Collector::Util;
10  
11 my $isvm;
12 BEGIN{
13 $isvm = MYDan::Collector::Util::qx( 'dmidecode' ) =~ /No SMBIOS nor DMI entry point found, sorry\./ ? 1 : 0;
14 };
15  
16  
17 sub co
18 {
19 my ( $this, @stat ) = shift;
20  
21 push @stat, [ qw( IFACE speed ) ];
22 return \@stat if $isvm;
23 my %eth = map { split /\s+/, $_, 2 } MYDan::Collector::Util::qx( 'ifconfig | grep ^eth' );
24  
25 for my $iface ( keys %eth )
26 {
27 my $info = MYDan::Collector::Util::qx( "ethtool $iface | grep Speed" );
28 push @stat, [ $iface, $info && $info =~ /:\s(\d+)\D+/ ? $1 : -1 ];
29 }
30  
31 return \@stat;
32 }
33  
34 1;