2004-06-22 06:37:04 +08:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Sigar;
|
|
|
|
|
|
|
|
my $sigar = new Sigar;
|
|
|
|
|
|
|
|
my $fslist = $sigar->file_system_list;
|
|
|
|
|
2004-09-19 02:02:54 +08:00
|
|
|
print "Filesystem\tSize\tUsed\tAvail\tUse%\tMounted on\tType\n";
|
2004-06-22 06:37:04 +08:00
|
|
|
|
|
|
|
for my $fs (@$fslist) {
|
|
|
|
my $dirname = $fs->dir_name;
|
2004-09-18 02:15:36 +08:00
|
|
|
my $usage;
|
|
|
|
|
|
|
|
#e.g. on win32 D:\ fails with "Device not ready"
|
|
|
|
#if there is no cd in the drive.
|
|
|
|
eval {
|
|
|
|
$usage = $sigar->file_system_usage($dirname);
|
|
|
|
} or next;
|
2004-06-22 06:37:04 +08:00
|
|
|
|
|
|
|
my $total = $usage->total;
|
|
|
|
my $used = $total - $usage->free;
|
|
|
|
my $avail = $usage->avail;
|
|
|
|
my $pct = $usage->use_percent * 100;
|
|
|
|
my $usePct;
|
|
|
|
|
|
|
|
if ($pct == 0) {
|
|
|
|
$usePct = "-"
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$usePct = $pct . '%';
|
|
|
|
}
|
|
|
|
|
|
|
|
print
|
|
|
|
$fs->dev_name . "\t" .
|
2004-09-19 02:02:54 +08:00
|
|
|
format_size($total) . "\t" .
|
|
|
|
format_size($used) . "\t" .
|
|
|
|
format_size($avail) . "\t" .
|
2004-06-22 06:37:04 +08:00
|
|
|
$usePct . "\t" .
|
|
|
|
$dirname . "\t" .
|
|
|
|
$fs->sys_type_name . "/" . $fs->type_name . "\n";
|
|
|
|
|
|
|
|
}
|
2004-09-19 02:02:54 +08:00
|
|
|
|
|
|
|
sub format_size {
|
|
|
|
my($size) = @_;
|
|
|
|
return Sigar::format_size($size * 1024);
|
|
|
|
}
|