Build a simple monitoring engine using PHP (III)-PHP source code

Source: Internet
Author: User
Tags php error php error log
Ec (2); V. Example ServiceLogger process the following is an example ServiceLogger process. When a service is stopped, it sends an email to a standby person: classEmailMe_ServiceLoggerimplementsServiceLogger {publicfunctionlog_service_event (ServiceCheck $ service) script ec (2); script

5. ServiceLogger process example

The following is an example ServiceLogger process. When a service is stopped, it is responsible for sending an email to a standby person:

Class EmailMe_ServiceLogger implements ServiceLogger {
Public function log_service_event (ServiceCheck $ service)
{
If ($ service-> current_status = ServiceCheck: FAILURE ){
$ Message = "Problem with {$ service-> description ()} rn ";
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;
}
}

If five consecutive failures occur, the process also sends a message to a backup address. Note that it does not implement a meaningful log_current_status () method.

Whenever you change the status of a service as follows, you should implement a ServiceLogger process written to the PHP Error Log:

Class ErrorLog_ServiceLogger implements ServiceLogger {
Public function log_service_event (ServiceCheck $ service)
{
If ($ service-> current_status ()! ==$ Service-> previus_status ()){
If ($ service-> current_status () === ServiceCheck: FAILURE ){
$ Status = 'low ';
}
Else {
$ Status = 'up ';
}
Error_log ("{$ service-> description ()} changed status to $ status ");
}
}
Public function log_current_status (ServiceCheck $ service)
{
Error_log ("{$ service-> description ()}: $ status ");
}
}

The log_current_status () method means that if the process sends a SIGUSR1 signal, it will copy its complete current status to your PHP error log.
  
The engine uses the following configuration file:


 
  
    Errorlog
    ErrorLog_ServiceLogger
  
  
    Emailme
    EmailMe_ServiceLogger
  
 
 
  
    HTTP_ServiceCheck
   
     OmniTI HTTP Check
     Http://www.omniti.com
     30
     900
   
   
     Errorlog
     Emailme

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.