Linux-Info

 view release on metacpan or  search on metacpan

lib/Linux/Info.pm  view on Meta::CPAN

    );

    $lxs->get(); # without to sleep

The initial statistics are stored to the temporary file:

    #> cat /tmp/pgswstats.yml
    ---
    pgfault: 397040955
    pgmajfault: 4611
    pgpgin: 21531693
    pgpgout: 49511043
    pswpin: 8
    pswpout: 272
    time: 1236783534.9328

Every time you call the script the initial statistics are loaded/stored from/to
the file. This could be helpful if you doesn't run it as daemon and if you want
to calculate the average load of your system since the last call.

To get more information about the statistics refer the different modules of the
distributions below:

lib/Linux/Info/PgSwStats.pm  view on Meta::CPAN

    my $file  = $self->{files};
    my %stats = ();

    my $filename =
      $file->{path} ? "$file->{path}/$file->{stat}" : $file->{stat};
    open my $fh, '<', $filename
      or croak "$class: unable to open $filename ($!)";

    while ( my $line = <$fh> ) {
        if ( $line =~ /^page\s+(\d+)\s+(\d+)$/ ) {
            @stats{qw(pgpgin pgpgout)} = ( $1, $2 );
        }
        elsif ( $line =~ /^swap\s+(\d+)\s+(\d+)$/ ) {
            @stats{qw(pswpin pswpout)} = ( $1, $2 );
        }
    }

    close($fh);

    # if paging and swapping are not found in /proc/stat
    # then let's try a look into /proc/vmstat (since 2.6)

    if ( !defined $stats{pswpout} ) {
        my $filename =
          $file->{path} ? "$file->{path}/$file->{vmstat}" : $file->{vmstat};
        open my $fh, '<', $filename
          or croak "$class: unable to open $filename ($!)";
        while ( my $line = <$fh> ) {
            next
              unless $line =~
              /^(pgpgin|pgpgout|pswpin|pswpout|pgfault|pgmajfault)\s+(\d+)/;
            $stats{$1} = $2;
        }
        close($fh);
    }

    return \%stats;
}

sub _deltas {
    my $self  = shift;

lib/Linux/Info/PgSwStats.pm  view on Meta::CPAN

=head1 DESCRIPTION

Linux::Info::PgSwStats gathers paging and swapping statistics from the virtual F</proc> filesystem (procfs).

For more information read the documentation of the front-end module L<Linux::Info>.

=head1 PAGING AND SWAPPING STATISTICS

Generated by F</proc/stat> or F</proc/vmstat>.

    pgpgin      -  Number of pages the system has paged in from disk per second.
    pgpgout     -  Number of pages the system has paged out to disk per second.
    pswpin      -  Number of pages the system has swapped in from disk per second.
    pswpout     -  Number of pages the system has swapped out to disk per second.

    The following statistics are only available by kernels from 2.6.

    pgfault     -  Number of page faults the system has made per second (minor + major).
    pgmajfault  -  Number of major faults per second the system required loading a memory page from disk.

=head1 METHODS

t/050-pgswstats.t  view on Meta::CPAN

use strict;
use warnings;
use Test::More;
use Linux::Info;

my @pgswstats = qw(
   pgpgin
   pgpgout
   pswpin
   pswpout
);

my $sys = Linux::Info->new();

if (!-r '/proc/diskstats' || !-r '/proc/partitions' || !-r '/proc/stat' || !-r '/proc/vmstat') {
    plan skip_all => "it seems that your system doesn't provide paging/swapping statistics";
    exit(0);
}



( run in 0.931 second using v1.01-cache-2.11-cpan-df04353d9ac )