File: diskusage.pl

package info (click to toggle)
libsys-statistics-linux-perl 0.66-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 424 kB
  • sloc: perl: 1,655; makefile: 2
file content (30 lines) | stat: -rwxr-xr-x 896 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/perl
use strict;
use warnings;
use Sys::Statistics::Linux;
use Sys::Statistics::Linux::DiskUsage;
$Sys::Statistics::Linux::DiskUsage::DF_CMD = 'df -hP';

my $sys  = Sys::Statistics::Linux->new(diskusage => 1);
my $stat = $sys->get;

# $stat->diskusage returns the first level keys of the
# statistic hash as a array. The first level keys are
# the disk names.
foreach my $disk ( $stat->diskusage ) { # Gimme the disk names

    print "Statistics for disk $disk:\n";

    # $stat->diskusage($disk) returns the seconds level keys of
    # the statistics. The second level keys are the statistic keys
    # for the passed disk.
    foreach my $key ( sort $stat->diskusage($disk) ) { # Gimme the statistic keys

        # $stat->diskusage($disk, $key) returns the value for the passed
        # disk and key.
        printf "   %-20s %s\n", $key, $stat->diskusage($disk, $key);

    }

}