documentation and attribution fixes
[scpubgit/System-Introspector.git] / lib / System / Introspector / Probe / DiskUsage.pm
1 package System::Introspector::Probe::DiskUsage;
2 use Moo;
3
4 use System::Introspector::Util qw(
5     lines_from_command
6     transform_exceptions
7 );
8
9 sub gather {
10     my ($self) = @_;
11     return transform_exceptions {
12         my @lines = lines_from_command ['df', '-aP'];
13         shift @lines; # header
14         my @rows;
15         for my $line (@lines) {
16             my %row;
17             @row{qw(
18                 filesystem
19                 blocks_1024
20                 used
21                 available
22                 capacity
23                 mount_point
24             )} = split m{\s+}, $line;
25             push @rows, \%row;
26         }
27         no warnings 'uninitialized';
28         return { disk_usage => [ sort {
29             ($a->{filesystem} cmp $b->{filesystem})
30             ||
31             ($a->{mount_point} cmp $b->{mount_point})
32         } @rows ] };
33     };
34 }
35
36 1;
37
38 __END__
39
40 =head1 NAME
41
42 System::Introspector::Probe::DiskUsage - Gather disk space usage data
43
44 =head1 DESCRIPTION
45
46 Uses C<df> to get data about current disk usage.
47
48 =head1 SEE ALSO
49
50 =over
51
52 =item L<System::Introspector>
53
54 =back
55
56 =head1 COPYRIGHT
57
58 Copyright (c) 2012 the L<System::Introspector>
59 L<AUTHOR|System::Introspector/AUTHOR>,
60 L<CONTRIBUTORS|System::Introspector/CONTRIBUTORS> and
61 L<SPONSORS|System::Introspector/SPONSORS>.
62
63 =head1 LICENSE
64
65 This library is free software and may be distributed under the same terms
66 as perl itself.
67
68 =cut