package System::Introspector::DiskUsage;
use Moo;

use System::Introspector::Util qw(
    lines_from_command
    transform_exceptions
);

sub gather {
    my ($self) = @_;
    return transform_exceptions {
        my @lines = lines_from_command ['df', '-aP'];
        shift @lines; # header
        my @rows;
        for my $line (@lines) {
            my %row;
            @row{qw(
                filesystem
                blocks_1024
                used
                available
                capacity
                mount_point
            )} = split m{\s+}, $line;
            push @rows, \%row;
        }
        return { disk_usage => \@rows };
    };
}

1;

__END__

=head1 NAME

System::Introspector::DiskUsage - Gather disk space usage data

=head1 DESCRIPTION

Uses C<df> to get data about current disk usage.

=head1 SEE ALSO

=over

=item L<System::Introspector>

=back

=cut

