扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:朱先忠编译 来源:天极开发 2007年10月21日
关键字:
class EmailMe_ServiceLogger implements ServiceLogger { public function log_service_event(ServiceCheck$service) { if($service->current_status ==ServiceCheck::FAILURE) { $message = "Problem with{$service->description()}\r\n"; mail('oncall@example.com', 'Service Event',$message); if($service->consecutive_failures() > 5) { mail('oncall_backup@example.com', 'Service Event', $message); } } } public function log_current_status(ServiceCheck$service){ return; } } |
class ErrorLog_ServiceLogger implements ServiceLogger { public function log_service_event(ServiceCheck$service) { if($service->current_status() !==$service->previous_status()) { if($service->current_status() ===ServiceCheck::FAILURE) { $status = 'DOWN'; } else { $status = 'UP'; } error_log("{$service->description()} changed status to $status"); } } public function log_current_status(ServiceCheck$service) { error_log("{$service->description()}: $status"); } } |
<config> <loggers> <logger> <id>errorlog</id> <class>ErrorLog_ServiceLogger</class> </logger> <logger> <id>emailme</id> <class>EmailMe_ServiceLogger</class> </logger> </loggers> <services> <service> <class>HTTP_ServiceCheck</class> <params> <description>OmniTI HTTP Check</description> <url>http://www.omniti.com</url> <timeout>30</timeout> <frequency>900</frequency> </params> <loggers> <logger>errorlog</logger> <logger>emailme</logger> </loggers> </service> <service> <class>HTTP_ServiceCheck</class> <params> <description>Home Page HTTP Check</description> <url>http://www.schlossnagle.org/~george</url> <timeout>30</timeout> <frequency>3600</frequency> </params> <loggers> <logger>errorlog</logger> </loggers> </service> </services> </config> |
选项 | 描述 |
[-f] | 引擎的配置文件的一个位置,默认是monitor.xml。 |
[-n] | 引擎允许的子进程池的大小,默认是5。 |
[-d] | 一个停用该引擎的守护功能的标志。在你编写一个把信息输出到stdout或stderr的调试ServiceLogger进程时,这是很有用的。 |
require_once "Service.inc"; require_once "Console/Getopt.php"; $shortoptions = "n:f:d"; $default_opts = array('n' => 5, 'f' =>'monitor.xml'); $args = getOptions($default_opts, $shortoptions,null); $fp = fopen("/tmp/.lockfile", "a"); if(!$fp || !flock($fp, LOCK_EX | LOCK_NB)) { fputs($stderr, "Failed to acquire lock\n"); exit; } if(!$args['d']) { if(pcntl_fork()) { exit; } posix_setsid(); if(pcntl_fork()) { exit; } } fwrite($fp, getmypid()); fflush($fp); $engine = new ServiceCheckRunner($args['f'],$args['n']); $engine->loop(); |