Skip to content

Instantly share code, notes, and snippets.

@rushipkar90
Created September 25, 2015 16:30
Show Gist options
  • Save rushipkar90/742f39fa047eeb41f8c0 to your computer and use it in GitHub Desktop.
Save rushipkar90/742f39fa047eeb41f8c0 to your computer and use it in GitHub Desktop.
diskusage.pl
#!/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/listaccts';
%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 "TOP 20 DISK USAGE\n\n";
foreach $account (@{$requestparsed->{acct}}) {
$disk = $account->{diskused};
$disk =~ s/M//g;
$disk *= 1024;
# Get the database size
#$user = $account->{user};
#@dbs = </var/lib/mysql/$user_*>;
#foreach $db (@dbs) {
# chomp($size = `du -s $db`);
# $disk += $size;
#}
$accounts{$account->{user}} = $disk;
#print "$account->{user}\n";
#print Dumper $account;
}
@sorted = sort { $accounts{$b} <=> $accounts{$a} } (keys(%accounts));
foreach $key (@sorted[0..19]) {
$disk = $accounts{$key} / 1024;
print "$key\t\t$disk M\n";
}
} else {
print "Disk Usage Request failed.\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment