Created
September 25, 2015 16:25
-
-
Save rushipkar90/b700fe7bec824d2b9d22 to your computer and use it in GitHub Desktop.
bandwidthusage.pl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use lib '/root/sysutils/modules'; | |
use XML::Simple; | |
use Data::Dumper; | |
use XMLAPIRequest; | |
chomp(my $hostname = `hostname`); | |
$xmlapi = XMLAPIRequest->new( | |
'HOSTNAME' => $hostname | |
); | |
$command = '/xml-api/showbw'; | |
%request = $xmlapi->dispatch($command); | |
$xml = XML::Simple->new(); | |
$requestparsed = $xml->XMLin($request{PAGE}); | |
%accounts = {}; | |
#print Dumper $requestparsed; | |
if ($request{RESULT} =~ /HTTP\/1.0 200 OK/) { | |
print "\nTOP 20 BANDWIDTH\n\n"; | |
foreach $account (@{$requestparsed->{bandwidth}{acct}}) { | |
$accounts{$account->{user}} = $account->{totalbytes}; | |
} | |
@sorted = sort { $accounts{$b} <=> $accounts{$a} } (keys(%accounts)); | |
foreach $key (@sorted[0..19]) { | |
$mbytes = int (($accounts{$key} / 1024) / 1024); | |
print "$key\t\t $mbytes M\n"; | |
} | |
} else { | |
print "Bandwidth Usage Request failed.\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment