Sys-Statistics-Linux

 view release on metacpan or  search on metacpan

lib/Sys/Statistics/Linux.pm  view on Meta::CPAN

In addition it's possible to pass a hash reference with options.

    my $lxs = Sys::Statistics::Linux->new(
        processes => {
            init => 1,
            pids => [ 1, 2, 3 ]
        },
        netstats => {
            init => 1,
            initfile => $file,
        },
    );

Option C<initfile> is useful if you want to store initial statistics on the filesystem.

    my $lxs = Sys::Statistics::Linux->new(
        cpustats => {
            init     => 1,
            initfile => '/tmp/cpustats.yml',
        },
        diskstats => {
            init     => 1,
            initfile => '/tmp/diskstats.yml',
        },
        netstats => {
            init     => 1,
            initfile => '/tmp/netstats.yml',
        },
        pgswstats => {
            init     => 1,
            initfile => '/tmp/pgswstats.yml',
        },
        procstats => {
            init     => 1,
            initfile => '/tmp/procstats.yml',
        },
    );

Example:

    #!/usr/bin/perl
    use strict;
    use warnings;
    use Sys::Statistics::Linux;

    my $lxs = Sys::Statistics::Linux->new(
        pgswstats => {
            init => 1,
            initfile => '/tmp/pgswstats.yml'
        }
    );

    $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. Do you understand? I hope so :)

To get more information about the statistics refer the different modules of the distribution.

    sysinfo     -  Collect system information              with Sys::Statistics::Linux::SysInfo.
    cpustats    -  Collect cpu statistics                  with Sys::Statistics::Linux::CpuStats.
    procstats   -  Collect process statistics              with Sys::Statistics::Linux::ProcStats.
    memstats    -  Collect memory statistics               with Sys::Statistics::Linux::MemStats.
    pgswstats   -  Collect paging and swapping statistics  with Sys::Statistics::Linux::PgSwStats.
    netstats    -  Collect net statistics                  with Sys::Statistics::Linux::NetStats.
    sockstats   -  Collect socket statistics               with Sys::Statistics::Linux::SockStats.
    diskstats   -  Collect disk statistics                 with Sys::Statistics::Linux::DiskStats.
    diskusage   -  Collect the disk usage                  with Sys::Statistics::Linux::DiskUsage.
    loadavg     -  Collect the load average                with Sys::Statistics::Linux::LoadAVG.
    filestats   -  Collect inode statistics                with Sys::Statistics::Linux::FileStats.
    processes   -  Collect process statistics              with Sys::Statistics::Linux::Processes.

=head1 METHODS

=head2 new()

Call C<new()> to create a new Sys::Statistics::Linux object. You can call C<new()> with options.
This options would be passed to the method C<set()>.

Without options

    my $lxs = Sys::Statistics::Linux->new();

Or with options

    my $lxs = Sys::Statistics::Linux->new( cpustats => 1 );

Would do nothing

    my $lxs = Sys::Statistics::Linux->new( cpustats => 0 );

It's possible to call C<new()> with a hash reference of options.

    my %options = (
        cpustats => 1,
        memstats => 1
    );

    my $lxs = Sys::Statistics::Linux->new(\%options);

=head2 set()

Call C<set()> to activate or deactivate options.

The following example would call C<new()> and initialize C<Sys::Statistics::Linux::CpuStats>
and delete the object of C<Sys::Statistics::Linux::SysInfo>.

    $lxs->set(
        processes =>  0, # deactivate this statistic



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