The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Proc::LoadMonitor - Load monitoring for worker processes

SYNOPSIS

 use Proc::LoadMonitor;

  # get monitor, starts in 'idle' state
  my $lmon = Proc::LoadMonitor->new;

  # some job queue with timeout (e.g redis BLPOP) which
  # blocks until a new job is available, or times out.
  #  
  while ( my $job = $some_queue->get_next_job() ) {

    if ($job) {
        $lmon->busy; # set monitor to 'busy';
        $job->do_it();
    }
    
    $lmon->idle; # set monitor to 'idle', increment loop count

    my $report = $lmon->report;
    
    # $report = {
    #     loops   => 781,       # number of loops
    #     jobs    => 674,       # number of processed jobs 
    #     load_05 => 0.650,     #  5 min. load avg. 
    #     load_10 => 0.510,     # 10 min. load avg. 
    #     load_15 => 0.414,     # 15 min. load avg.
    #     state   => 'idle',    # 'busy'/'idle'
    #     total   => 110566.19  # total run time    
    # }

  }
  

DESCRIPTION

This module keeps track of idle and busy times in a worker process and calculates 5, 10 and 15 minutes load averages.

busy

Set state to busy.

idle

Set state to idle and increment the loop counter.

state

Returns the state which may be busy or idle.

loops

Returns the loop count.

jobs

Returns the number of jobs processed so far.

report

Returns a report (hash) containing loops, jobs, total (total run time in sec.), load_05 (5 min. load average), load_10 (10 min. load average) and load_15 (15 min. load average).

AUTHOR

Michael Langner (cpan:MILA)

COPYRIGHT

Copyright (c) 2015 the Proc::LoadMonitor "AUTHOR".

LICENSE

This library is free software and may be distributed under the same terms as perl itself. See http://dev.perl.org/licenses/.