Apache-Watchdog-RunAway
view release on metacpan or search on metacpan
package Apache::Watchdog::RunAway;
$Apache::VMonitor::VERSION = '1.00';
use strict;
BEGIN {
use constant MP2 => eval { require mod_perl; $mod_perl::VERSION > 1.99 };
die "mod_perl is required to run this module: $@" if $@;
if (MP2) {
require APR::Pool;
} else {
# nada
}
}
use Apache::Scoreboard ();
use Symbol ();
if (MP2 && require Apache::MPM && Apache::MPM->is_threaded()) {
die __PACKAGE__ . " is suitable to be used only under prefork MPM";
}
use subs qw(debug log_error);
########## user configurable variables #########
# timeout before counted as hang (in seconds)
# 0 means deactivated
$Apache::Watchdog::RunAway::TIMEOUT = 0;
# polling intervals in seconds
$Apache::Watchdog::RunAway::POLLTIME = 60;
# debug mode
$Apache::Watchdog::RunAway::DEBUG = 0;
# lock file
$Apache::Watchdog::RunAway::LOCK_FILE = "/tmp/safehang.lock";
# log file
$Apache::Watchdog::RunAway::LOG_FILE = "/tmp/safehang.log";
# scoreboard URL
$Apache::Watchdog::RunAway::SCOREBOARD_URL = "http://localhost/scoreboard";
# give details about the request that was hanging
$Apache::Watchdog::RunAway::VERBOSE = 0;
########## internal variables #########
# request processing times cache
my %req_proc_time = ();
# current request number
my %req_number = ();
my $log_fh;
# check whether the monitor is already running
# returns the PID if lockfile exists
##############
sub is_running {
return 0 unless -e $Apache::Watchdog::RunAway::LOCK_FILE;
my $pid = get_proc_pid();
warn <<EOT if $Apache::Watchdog::RunAway::DEBUG;
$0 is already running (proc $pid).
Locked in $Apache::Watchdog::RunAway::LOCK_FILE.
EOT
return $pid;
}
# returns the PID if lockfile exists or 0
################
( run in 0.331 second using v1.01-cache-2.11-cpan-bbe5e583499 )