|
From: Olivier A. <oli...@co...> - 2011-06-14 12:12:55
|
hello
someone in my compagnie need to get the volume of traffic on interfaces. As far as I know the only oid I have it the IfInOctets and IfOutOctets.
That's good but reading a volume in octets is not really human readable. Some solution exist with devmon ? May I implement a need transform method
like HUMAN for exemple to do this ? Following :
sub octets_to_human
2 {
4
5 my $size = shift;
6
7 if ($size > 1099511627776) # TiB: 1024 GiB
8 {
9 return sprintf("%.2f TiB", $size / 1099511627776);
10 }
11 elsif ($size > 1073741824) # GiB: 1024 MiB
12 {
13 return sprintf("%.2f GiB", $size / 1073741824);
14 }
15 elsif ($size > 1048576) # MiB: 1024 KiB
16 {
17 return sprintf("%.2f MiB", $size / 1048576);
18 }
19 elsif ($size > 1024) # KiB: 1024 B
20 {
21 return sprintf("%.2f KiB", $size / 1024);
22 }
23 else # bytes
24 {
25 return sprintf("%.2f bytes", $size);
26 }
27 }
what do you think ?
oau
|