use reusable I/O utils, more solid error handling for DiskUsage probe
[scpubgit/System-Introspector.git] / lib / System / Introspector / DiskUsage.pm
1 package System::Introspector::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         return { disk_usage => \@rows };
28     };
29 }
30
31 1;
32
33 __END__
34
35 =head1 NAME
36
37 System::Introspector::DiskUsage - Gather disk space usage data
38
39 =head1 DESCRIPTION
40
41 Uses C<df> to get data about current disk usage.
42
43 =head1 SEE ALSO
44
45 =over
46
47 =item L<System::Introspector>
48
49 =back
50
51 =cut
52