Exemple #1
0
 public function doMonitorAsJobs()
 {
     $canCheckTime = time() - 60;
     $ids = $this->getCheckServiceIds($canCheckTime);
     $cmd = '';
     if ($ids) {
         Ym_Logger::info('Start monitor check:-----------------------------------------------------');
         foreach ($ids as $id) {
             $status = isset($id['status']) ? $id['status'] : 3;
             //3默认为unknown
             $theTime = $id['next_check_time'] ? $id['next_check_time'] : time();
             $lastTime = $id['last_check_time'] ? $id['last_check_time'] : $theTime - 60;
             $lastNotifyTime = $id['last_notify_time'] ? $id['last_notify_time'] : 0;
             $monitorApi = $id['monitor_api'] ? $id['monitor_api'] : '';
             if (!$monitorApi) {
                 Ym_Logger::error('Unknow monitor api on service_id : ' . $id["service_id"] . '!');
                 continue;
             }
             $cmd = '/alarm/monitorscript/' . $monitorApi . '/id/';
             $cmd .= $id['service_id'] . '/lastStatus/' . $status;
             $cmd .= '/lastTime/' . $lastTime . '/currentTime/' . $theTime . '/lastNotifyTime/' . $lastNotifyTime;
             Ym_CommonTool::phpCli($cmd, TRUE, FALSE);
         }
         Ym_Logger::info("End monitor check:-----------------------------------------------------");
     }
     return FALSE;
 }
Exemple #2
0
 public static function showError($message, $file)
 {
     $logConfig = array('logPath' => '/tmp/', 'logFile' => $file, 'handler' => 'file', 'ifCacheHandler' => TRUE);
     Ym_Logger::init($logConfig);
     Ym_Logger::info($message);
     exit($message);
 }
 /**
 * 
 * 检测脚本主要程序(只需要编写该方法即可)
 * 
 * return array(
     		"time"	=>	$checkTime,
     		"code"	=>	$code,
     		"ip"	=>  $ip,
     		"app"	=>  $app,
     		"msg"	=>	$msg,
     		"logid" => 	$logid,
     		"log" 	=> 	$log
     	);
 */
 public function getCheckResult($monitorConfig, $lastTime, $currentTime)
 {
     if (empty($monitorConfig)) {
         Ym_CommonTool::myoutput(FALSE, 'get monitor data error or empty!');
     }
     $id = isset($monitorConfig['monitor_app']) ? $monitorConfig['monitor_app'] : '';
     $ip = isset($monitorConfig['monitor_ip']) ? $monitorConfig['monitor_ip'] : '';
     $app = isset($monitorConfig['app_name']) ? $monitorConfig['app_name'] : 'system';
     $service = isset($monitorConfig['monitor_service']) ? $monitorConfig['monitor_service'] : '';
     $param = isset($monitorConfig['monitor_param']) ? explode("\n", $monitorConfig['monitor_param']) : '';
     $maxTime = $this->plugins(array('currentTime' => $currentTime, 'app' => $app));
     $checkTime = strtotime(date('Y-m-d H:i', $maxTime));
     if ($checkTime <= $lastTime) {
         Ym_Logger::info('*weblog.' . $service . ' checktime: ' . $checkTime . ' <= Last: ' . $lastTime . ', pass!*');
         $checkTime = strtotime(date('Y-m-d H:i', $currentTime));
     }
     $model = new Model_Alarm_Monitorscript();
     $code = 0;
     $msg = array();
     if (count($param) > 0) {
         foreach ($param as $v) {
             $arr = explode('=', $v);
             $key = isset($arr[0]) ? $arr[0] : 'error';
             $alarm = isset($arr[1]) ? $arr[1] : 100;
             $return = $model->{__FUNCTION__}($key, $id, $lastTime, $checkTime);
             if (isset($return['num']) and $return['num'] >= $alarm) {
                 $msg[] = array("key" => $key, "num" => $return['num'], "alarm" => $alarm, "logid" => $return['content_id'], "log" => $return['sample']);
                 $code = 2;
             } else {
                 $num = (isset($return['num']) and $return['num']) ? $return['num'] : 0;
                 $msg[] = array("key" => $key, "num" => $num, "alarm" => $alarm);
             }
         }
     }
     $status_detail = '';
     $logid = 0;
     $log = '';
     foreach ($msg as $msgd) {
         $logid .= isset($msgd['logid']) ? $msgd['logid'] . '<br/>' : '';
         $log .= isset($msgd['log']) ? str_replace($msgd['key'], '<font color="red">' . $msgd['key'] . '</font>', $msgd['log']) . '<br/>' : '';
         if ($logid) {
             $color = 'red';
         } else {
             $color = 'green';
         }
         $status_detail .= 'Key:' . $msgd['key'];
         $status_detail .= ' Num:<font color="' . $color . '">' . $msgd['num'] . '</font>';
         $status_detail .= ' Alarm:' . $msgd['alarm'];
         $status_detail .= '<br/>';
     }
     $thealarm = 'Time:' . date('Y/m/d H:i:s', $checkTime);
     $thealarm .= ' Code:' . $code;
     $thealarm .= ' IP:' . long2ip($ip);
     $thealarm .= ' App:' . $app;
     $thealarm .= ' Msg:"' . rtrim($status_detail, '<br/>') . '"';
     Ym_Logger::info($thealarm);
     return array("time" => $checkTime + 10, "code" => $code, "ip" => $ip, "app" => $app, "msg" => rtrim($status_detail, '<br/>'), "logid" => $logid, "log" => $log);
 }
Exemple #4
0
<?php

date_default_timezone_set('Asia/Shanghai');
$app = Ym_Init::init('monitor');
$app->run();
// run info to record
$runInfo = 'cost : ' . Ym_Timer::getResult('cost') . ' s , mem  : ' . Ym_Timer::getResult('mem') . ' KB';
if (YPP_APP_ENV != 'pro') {
    echo $runInfo, PHP_EOL;
}
Ym_Logger::info($runInfo);
Exemple #5
0
 public function sendBySms($to, $title, $body, $ip, $app)
 {
     Ym_Logger::info('Sendsms#' . $to);
     Sys_Message::send('sms', $to, $title, $body, $ip, $app);
 }
 /**
  * 
  * 检测脚本主要程序(只需要编写该方法即可)
  */
 public function getCheckResult($monitorConfig, $lastTime, $currentTime)
 {
     if (empty($monitorConfig)) {
         Ym_CommonTool::myoutput(FALSE, 'get monitor data error or empty!');
     }
     $model = new Model_Alarm_Monitorscript();
     $id = isset($monitorConfig['monitor_app']) ? $monitorConfig['monitor_app'] : '';
     $ip = isset($monitorConfig['monitor_ip']) ? $monitorConfig['monitor_ip'] : '';
     $app = isset($monitorConfig['app_name']) ? $monitorConfig['app_name'] : 'system';
     $param = isset($monitorConfig['monitor_param']) ? $monitorConfig['monitor_param'] : '';
     $checkTime = strtotime(date('Y-m-d H:i', $currentTime));
     $code = 0;
     $maxTime = 0;
     $msg = array();
     $logid = 0;
     $log = '';
     $string = '';
     $arr = explode('=', $param);
     $key = isset($arr[0]) ? $arr[0] : 'error';
     $alarm = isset($arr[1]) ? $arr[1] : 0;
     $cmd = '/reportapi/accesslog/NumberOfNode';
     $return = Ym_CommonTool::phpCli($cmd, FALSE, TRUE);
     $data = json_decode($return, TRUE);
     //$nodestr = Ym_Config::getAppItem("monitor:mongo.accesslog.tables");
     //$nodes = explode(',', $nodestr);
     $i = 0;
     foreach ($data['data']['series'] as $k => $v) {
         if ($i < 3 and $v <= $alarm) {
             $code = 2;
         }
         $string .= $k . ' : ' . $v . '<br/>';
         $i++;
     }
     $string .= 'alarm_num:' . $alarm;
     $thealarm = 'Time:' . date('Y/m/d H:i:s', $currentTime);
     $thealarm .= ' Code:' . $code;
     $thealarm .= ' IP:' . long2ip($ip);
     $thealarm .= ' App:' . $app;
     $thealarm .= ' Msg:"' . $string;
     Ym_Logger::info(strip_tags($thealarm));
     return array("time" => $currentTime, "code" => $code, "ip" => $ip, "app" => $app, "msg" => $string, "logid" => $logid, "log" => $log);
 }
Exemple #7
0
 /**
  * 
  * yafclient exec Add by zhangy
  * @param str $url
  * @param bool $asJob
  */
 public function phpCli($url = '', $asJob = TRUE, $return = TRUE)
 {
     $job = "";
     $out = ">/dev/null 2>&1";
     $phpcmd = "/bin/php";
     $yafClient = Ym_Config::getAppItem("application:application.client");
     $requestUri = "request_uri=" . $url;
     if ($asJob) {
         $job = "&";
     }
     if ($return) {
         $out = "";
     }
     $cmd = trim($phpcmd . " " . $yafClient . " '" . $requestUri . "' " . $out . " " . $job);
     Ym_Logger::info($cmd);
     return system($cmd);
 }
 public function sendByEmail($emailList, $title, $body, $ip, $app)
 {
     Ym_Logger::info('test---Sendmail#' . $emailList);
     $r = Sys_Message::send('mail', $emailList, $title, $body, $ip, $app);
     var_dump(json_decode(urldecode($r), true));
 }