package System::Introspector::DiskUsage;
use Moo;
+use System::Introspector::Util qw(
+ lines_from_command
+ transform_exceptions
+);
+
sub gather {
my ($self) = @_;
- my @lines = `df -aP`;
- shift @lines; # header
- chomp @lines;
- 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 \@rows;
+ 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;
use System::Introspector::DiskUsage;
my $probe = System::Introspector::DiskUsage->new;
-my $data = $probe->gather;
+
+my $result = $probe->gather;
+ok $result, 'received data';
+my $data = $result->{disk_usage};
+ok $data, 'received disk usage data';
ok scalar(@$data), 'received data';
my @fields = qw( filesystem blocks_1024 used available capacity mount_point );