Jifty::Plugin::Monitoring.3pm

Langue: en

Autres versions - même langue

Version: 2008-04-08 (ubuntu - 07/07/09)

Section: 3 (Bibliothèques de fonctions)

NAME

Jifty::Plugin::Monitoring - Provides a framework for profiling and monitoring services

SYNOPSIS

In your config.yml:
   Plugins:
     - Monitoring: {}
 
 

By writing modules, and scheduling the running of "jifty cron", repeating events can be scheduled at various frequencies. It also provides functionality for sampling and recording profiling or usage statistics from your jifty application.

DESCRIPTION

The configuration in config.yml accepts one possible parameter, "path", which should be the base class under which all monitoring classes are found. This defaults to "AppName::Monitor". "path" may also be an array refence of classes to search under.

Each class monitoring class should "use Jifty::Plugin::Monitoring". This will import several functions, which allow you to write monitoring code as follows:

   use Jifty::Plugin::Monitoring;
   monitor users => every 30 => minutes, sub {
       my $monitor = shift;
       my $collection = AppName::Model::UserCollection->new;
       $collection->unlimit;
       data_point all => $collection->count;
 
       data_point yaks => int(rand(100));
   };
 
 

Monitors must have distinct names. Time units supported by this syntax include the singular and plural forms of "minute", "hour", "day", "week", "month", and "year".

EXPORTED FUNCTIONS

These methods are used in your monitoring classes to define monitors.

every

Syntactic sugar helper method, which allows you to write:
   every 3 => minutes, sub { ... };
 
 

or

   every qw/3 minutes/, sub { ... };
 
 

monitor

Syntactic sugar which defines a monitor. Use it in conjunction with ``every'':
   monitor "name", every qw/3 minutes/ => sub { ... };
 
 

data_point [CATEGORY,] NAME, VALUE

Records a data point, associating "NAME" to "VALUE" at the current time. "CATEGORY" defaults to the name of the monitor that the data point is inside of.

previous [CATEGORY,] NAME

Returns the most recent valeu for the data point of the given "NAME" and "CATEGORY". "CATEGORY" defaults to the name of the current monitor.

timer MECH, URL

Uses Time::HiRes to time how long it takes the given WWW::Mechanize object "MECH" to retrueve the given "URL". Returns the number of seconds elapsed.

Other Syntactic Sugar Methods

The following methods simply return themselves:
minute, minutes
hour, hours
day, days
week, weeks
month, months
year, years

OBJECT METHODS

These are primarily used by Jifty::Plugin::Monitoring::Command::Cron; you will not need to call these in most uses of this plugin.

init

Looks for and loads all monitoring classes. During the loading process, the monitors defined in each class are found and stored for later reference.

add_monitor NAME COUNT UNIT SUB

A class method used to add a monitor with the given "NAME" and "SUB", which is scheduled to be run every "COUNT" "UNIT"s.

last_run NAME

Looks up and returns the Jifty::Plugin::Monitoring::Model::LastRun object for this monitor; creates one if one does not exist, and sets it to the previous round time it would have run.

current_user

Monitors presumable run as superuser; thus, this method returns the application's superuser object.

current_monitor

Returns a hashref, with keys of "name", "sub", "count", and "units", which describe the monitor which is crrently running, if any.

now

For consistency, the current concept of ``now'' is fixed while the monitor is running. Use this method to determine when ``now'' is.

run_monitors

For each monitor that we know of, checks to see if it is due to be run, and runs it if it is.

lock

Attempt to determine if there are other monitoring processes running. If there are, we return false. This keeps a long-running monitor from making later jobs pile up.

DESTROY

On destruction, remove the lockfile.