-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnicstati86.pl
executable file
·51 lines (36 loc) · 1.68 KB
/
nicstati86.pl
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
#!/usr/bin/perl
#
use Sun::Solaris::Kstat;
$iface = '';
my $kstat = Sun::Solaris::Kstat->new();
#my @inst=`dladm show-aggr -p |grep link | cut -d'=' -f 3 | awk '{print \$1}' `;
my @inst=`dladm show-dev | grep "link: up" | grep -v usb | awk '{print \$1}' `;
#my @inst="ixgbe0";
foreach $a (@inst) {
chomp($a);
my($a_iface) = $a =~ /^(.*?)\d+$/;
my($a_i) = $a =~ /(\d+)$/;
($t_stats{$a}{rbytes64}, $t_stats{$a}{obytes64}) = @{$kstat->{$a_iface}{$a_i}{mac}}{qw(rbytes64 obytes64)};
$t_stats{$a}{ifspeed} = $kstat->{$a_iface}{$a_i}{mac}{ifspeed}/8;
}
while (1)
{
sleep 1;
if ($kstat->update()) { }
foreach $interface (@inst)
{
chomp($interface);
my($iface) = $interface =~ /^(.*?)\d+$/;
my($inst) = $interface =~ /(\d+)$/;
($stats{$interface}{rbytes64}, $stats{$interface}{obytes64}) = @{$kstat->{$iface}{$inst}{mac}}{qw(rbytes64 obytes64)};
$rbytes = eval { ($stats{$interface}{rbytes64} - $t_stats{$interface}{rbytes64}) };
$obytes = eval { ($stats{$interface}{obytes64} - $t_stats{$interface}{obytes64}) };
$rpct = eval { (($stats{$interface}{rbytes64} - $t_stats{$interface}{rbytes64}) / $t_stats{$interface}{ifspeed}) * 100 };
$opct = eval { (($stats{$interface}{obytes64} - $t_stats{$interface}{obytes64}) / $t_stats{$interface}{ifspeed}) * 100 };
printf ("CHANGE_ME.net.$iface$inst.rbytes $rbytes \n");
printf ("CHANGE_ME.net.$iface$inst.obytes $obytes \n");
printf ("CHANGE_ME.net.$iface$inst.rpct %.2f \n", $rpct);
printf ("CHANGE_ME.net.$iface$inst.opct %.2f \n", $opct);
$t_stats{$interface}{rbytes64} = $stats{$interface}{rbytes64}; $t_stats{$interface}{obytes64} = $stats{$interface}{obytes64};
}
}