Skip Menu |

This queue is for tickets about the Sys-Statistics-Linux CPAN distribution.

Report information
The Basics
Id: 122630
Status: new
Priority: 0/
Queue: Sys-Statistics-Linux

People
Owner: Nobody in particular
Requestors: ACFEREN [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in:
  • 0.01
  • 0.02
  • 0.03
  • 0.04
  • 0.05
  • 0.06
  • 0.07
  • 0.09_01
  • 0.09_02
  • 0.09_03
  • 0.09_04
  • 0.09_05
  • 0.09_06
  • 0.09_09
  • 0.09_10
  • 0.09_11
  • 0.09_12
  • 0.09_13
  • 0.09_14
  • 0.09_15
  • 0.09_16
  • 0.09_17
  • 0.10
  • 0.11
  • 0.11_01
  • 0.11_02
  • 0.11_03
  • 0.12
  • 0.13
  • 0.14
  • 0.15
  • 0.16
  • 0.17
  • 0.18
  • 0.18_01
  • 0.19
  • 0.20
  • 0.21
  • 0.21_01
  • 0.21_02
  • 0.22
  • 0.23
  • 0.24
  • 0.25
  • 0.26
  • 0.28
  • 0.32
  • 0.33
  • 0.34
  • 0.36
  • 0.37
  • 0.38
  • 0.39_01
  • 0.40
  • 0.41
  • 0.42
  • 0.43
  • 0.44_01
  • 0.44_02
  • 0.44_03
  • 0.45
  • 0.46
  • 0.47
  • 0.48
  • 0.48_01
  • 0.48_02
  • 0.49
  • 0.50
  • 0.51_01
  • 0.52
  • 0.53_01
  • 0.54
  • 0.55_01
  • 0.55_02
  • 0.56
  • 0.57_01
  • 0.57_02
  • 0.57_03
  • 0.57_04
  • 0.58
  • 0.59
  • 0.59_01
  • 0.59_02
  • 0.60
  • 0.61
  • 0.62
  • 0.63
  • 0.64_1
  • 0.64_2
  • 0.65
  • 0.66
Fixed in: (no value)



Subject: Sys::Statistics::Linux::DiskUsage can't report on multiple mountpoints on the same 'Filesystem'
The df command used to get DiskUsage details returns 6 columns (Filesystem, 1024-blocks, Used, Available, Capacity, and Mounted on). The first column, Filesystem, is used as the key for the hash of statistics returned by Sys::Statistics::Linux::DiskUsage->get(). This generally works fine for actual disks since they all have unique filesystem names. However, there are situations where the filesystem names are not all unique. For example if you create more than one tmpfs ram drive you can only get the stats for the last one returned by df since all tmpfs mounts report "tmpfs" as their filesystem. I've attached a patched Sys-Statistics-Linux-0.66/lib/Sys/Statistics/Linux/DiskUsage.pm which fixes this issue. The patched file also changes to the three argument version of open.
Subject: DiskUsage.pm
=head1 NAME Sys::Statistics::Linux::DiskUsage - Collect linux disk usage. =head1 SYNOPSIS use Sys::Statistics::Linux::DiskUsage; my $lxs = new Sys::Statistics::Linux::DiskUsage; my $stat = $lxs->get; =head1 DESCRIPTION Sys::Statistics::Linux::DiskUsage gathers the disk usage with the command C<df>. For more information read the documentation of the front-end module L<Sys::Statistics::Linux>. =head1 DISK USAGE INFORMATIONS Generated by F</bin/df -kP>. total - The total size of the disk. usage - The used disk space in kilobytes. free - The free disk space in kilobytes. usageper - The used disk space in percent. mountpoint - The moint point of the disk. =head2 GLOBAL VARS If you want to change the path or arguments for C<df> you can use the following variables... $Sys::Statistics::Linux::DiskUsage::DF_PATH = '/bin'; $Sys::Statistics::Linux::DiskUsage::DF_CMD = 'df -akP'; Example: use Sys::Statistics::Linux; use Sys::Statistics::Linux::DiskUsage; $Sys::Statistics::Linux::DiskUsage::DF_CMD = 'df -akP'; my $sys = Sys::Statistics::Linux->new(diskusage => 1); my $disk = $sys->get; =head1 METHODS =head2 new() Call C<new()> to create a new object. my $lxs = Sys::Statistics::Linux::DiskUsage->new; It's possible to set the path to df. Sys::Statistics::Linux::DiskUsage->new( cmd => { # This is the default path => '/bin', df => 'df -kP 2>/dev/null', } ); =head2 get() Call C<get()> to get the statistics. C<get()> returns the statistics as a hash reference. my $stat = $lxs->get; =head1 EXPORTS No exports. =head1 SEE ALSO B<df(1)> =head1 REPORTING BUGS Please report all bugs to <jschulz.cpan(at)bloonix.de>. =head1 AUTHOR Jonny Schulz <jschulz.cpan(at)bloonix.de>. =head1 COPYRIGHT Copyright (c) 2006, 2007 by Jonny Schulz. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut package Sys::Statistics::Linux::DiskUsage; use strict; use warnings; use Carp qw(croak); our $VERSION = '0.14'; our $DF_PATH = undef; our $DF_CMD = undef; sub new { my $class = shift; my $opts = ref($_[0]) ? shift : {@_}; my %self = ( cmd => { path => '/bin', df => 'df -kP 2>/dev/null', } ); foreach my $p (keys %{ $opts->{cmd} }) { $self{cmd}{$p} = $opts->{cmd}->{$p}; } return bless \%self, $class; } sub get { my $self = shift; my $class = ref $self; my $cmd = $self->{cmd}; my $df_cmd = $DF_CMD || $cmd->{df}; my (%disk_usage); local $ENV{PATH} = $DF_PATH || $cmd->{path}; # Changed to the three argument version of open. Not using the # three argument version is a little dangerous when allowing the # user to specify the df_cmd. open my $fh, '-|', $df_cmd or croak "$class: unable to execute '$df_cmd' ($!)"; # filter the header {my $null = <$fh>;} # This is the least bad patch I could think of. Previously the # %disk_usage hash was keyed on just the Filesystem name ($1), but # for tmpfs (and others) it is possible to have multiple lines for # the same Filesystem. Using seen we append __$seencnt to the # filesystem name for each instance after the first. This means # that any code relying on the current hashkey will continue to # work for non-duplicated filesystem names. Existing code never # really worked when filesystem names were duplicated so I don't # feel too badly about any breakage there. I also added a # filesystem hashkey to the stats so we don't need to rely on # parsing off the "__$seencnt" from the new hashkey. my %seen; # How many times have we seen a Filesystem? while (my $line = <$fh>) { next unless $line =~ /^(.+?)\s+(.+)$/; my ($fs, $fs_key) = ($1,$1); $fs_key .= "__$seen{$fs}" if $seen{$fs}++; @{$disk_usage{$fs_key}}{qw( filesystem total usage free usageper mountpoint )} = ( split /\s+/, $line )[0..5]; $disk_usage{$fs_key}{usageper} =~ s/%$//; } close($fh); return \%disk_usage; } 1; __END__ # Local Variables: *** # mode:CPerl *** # cperl-indent-level:4 *** # perl-indent-level:4 *** # tab-width: 4 *** # indent-tabs-mode: nil *** # End: *** # # vim: ts=4 sw=4 expandtab