public function getAccessLog($tables, $stepTime) { $returns = array(); $nodes = count($tables); $slave = false; $recordTime = $this->logPersistentService->getRecordTime($this->logType, $stepTime); $from = intval($recordTime); $to = intval($from + $stepTime); foreach ($tables as $n => $table) { if ($nodes > 2 and $n == $nodes - 1) { $slave = true; } $after = $this->dataModel->getAfter($table, $to, $slave); if (!$after) { Ym_Logger::error('Access after false endTime: ' . date('Y-m-d H:i:s', $to)); break; // return false; } } $this->logPersistentService->updateRecordTime($this->logType, $to); foreach ($tables as $table) { $result = $this->dataModel->getData($table, $from, $to); $returns = array_merge($returns, $result); } return $returns; }
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; }
public static function output($flag = true, $msg = '', $data = array()) { if ($flag) { $out = array('flag' => 'success', 'msg' => $msg, 'data' => $data); } else { $out = array('flag' => 'error', 'msg' => $msg, 'data' => $data); Ym_Logger::error($msg); } Ym_CommonTool::output(NULL, $out, 'json'); }
private function output($flag = TRUE, $msg = '', $data = array()) { if ($flag) { $out = array('flag' => 'success', 'msg' => $msg, 'data' => $data); } else { $out = array('flag' => 'error', 'msg' => $msg, 'data' => $data); Ym_Logger::error($msg); } Ym_CommonTool::output($this, $out, 'json'); }
public static function outputJsonp($flag = TRUE, $msg = '', $data = array(), $obj = NULL) { // output json {"flag":"error","msg":"","data":[]} if ($flag) { $out = array('flag' => 'success', 'msg' => $msg, 'data' => $data); } else { $out = array('flag' => 'error', 'msg' => $msg, 'data' => $data); Ym_Logger::error($msg); } Ym_CommonTool::output($obj, $out, 'jsonp'); exit; }
/** * 发送消息 * * @param string $type * @param $to * @param $subject * @param $body */ public static function send($type, $to, $subject, $body, $ip, $app = 'monitor') { switch ($type) { case 'mail': Ym_Logger::debug('------------------sendMail to:' . $to); $result = self::sendMail($to, $subject, $body); break; case 'sms': Ym_Logger::debug('------------------sendSms to:' . $to); $result = self::sendSms($to, $ip, $subject, $app); break; } return $result; }
public function getAfter($table, $time, $slave = false) { $returns = false; $timeout = 30; $slaveLimit = 10; if ($slave) { $d = $this->getData($table, $time, $time); if (count($d) < $slaveLimit) { return TRUE; } } for ($i = 0; $i < $timeout; $i++) { // 获取范围外数据 $this->mongoDao = new Dao_Mongo($this->logType); $this->mongoDao->orderBy(array("time" => -1)); $this->mongoDao->limit(1); $data = $this->mongoDao->get($table); if (count($data) < 1) { $returns = true; } else { $lastData = current($data); $lastTime = isset($lastData['time']) ? $lastData['time']->sec : 0; if ((int) abs($lastTime - $time) >= $timeout) { $returns = true; break; } if ($lastTime < $time) { Ym_Logger::error(date('Y-m-d H:i:s', $time) . ' need wait for ' . $table . ' ' . date('Y-m-d H:i:s', $lastTime)); } if ($lastTime > $time) { $returns = true; break; } else { sleep(1); continue; } } } return $returns; }
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(); $serviceId = isset($monitorConfig['id']) ? $monitorConfig['id'] : ''; $log_app_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']) ? $monitorConfig['monitor_param'] : ''; $checkTime = strtotime(date('Y-m-d H:i', $currentTime)); $code = 0; $maxTime = 0; $msg = array(); $logid = 0; $log = ''; $string = ''; //parse the params $alarm_arr = array(); $param_arr = explode("\n", $param); foreach ($param_arr as $v) { $arr = explode('=', $v); $key = isset($arr[0]) ? $arr[0] : 'error'; $alarm = isset($arr[1]) ? $arr[1] : 0; $alarm_arr[$key] = $alarm; } //cpu load $cpuLoad = `cat /proc/loadavg`; $mem = `free -m | grep Mem |awk -F' ' '{print \$4}'`; $disk = `df -h | awk -F' ' '{print\$5}' | grep -v Use |xargs`; $accessprocess = `ps -ef | grep 'accesslog' | grep -v grep | wc -l`; $weblogprocess = `ps -ef | grep 'weblog' | grep -v grep | wc -l`; $memalarm = isset($alarm_arr['mem']) ? $alarm_arr['mem'] : 100; if ($mem) { if ((int) $mem <= $memalarm) { $code = 1; } } $cpualarm = isset($alarm_arr['cpu']) ? $alarm_arr['cpu'] : 10; if ($cpuLoad) { $d = explode(' ', $cpuLoad); if ((int) $d[0] > $cpualarm) { $code = 2; } } $diskalarm = isset($alarm_arr['disk']) ? $alarm_arr['disk'] : 80; if ($disk) { foreach (explode(' ', $disk) as $v) { if ((int) trim($v, '%') > $diskalarm) { $code = 2; } } } $processAlarm = isset($alarm_arr['accessnum']) ? $alarm_arr['accessnum'] : 20; if ($accessprocess) { if ((int) $accessprocess >= $processAlarm or (int) $accessprocess == 0) { $code = 2; } } $processAlarm1 = isset($alarm_arr['weblognum']) ? $alarm_arr['weblognum'] : 20; if ($weblogprocess) { if ((int) $weblogprocess >= $processAlarm1 or (int) $weblogprocess == 0) { $code = 2; } } $string .= 'cpuload:' . $cpuLoad . ' alarm:' . $cpualarm . '<br/>'; $string .= 'mem:' . $mem . ' alarm:' . $memalarm . '<br/>'; $string .= 'disk:' . $disk . ' alarm:' . $diskalarm . '<br/>'; $string .= 'accessnum:' . $accessprocess . ' alarm:' . $processAlarm . '<br/>'; $string .= 'weblognum:' . $weblogprocess . ' alarm:' . $processAlarm1 . '<br/>'; $thealarm = ' Id:' . $serviceId; $thealarm .= ' Time:' . date('Y/m/d H:i:s', $checkTime); $thealarm .= ' Code:' . $code; $thealarm .= ' IP:' . long2ip($ip); $thealarm .= ' App:' . $app; $thealarm .= ' Msg:"' . $string; Ym_Logger::debug($thealarm); return array("time" => $currentTime, "code" => $code, "ip" => $ip, "app" => $app, "msg" => $string, "logid" => $logid, "log" => $log); }
/** * * 检测脚本主要程序(只需要编写该方法即可) */ public function getCheckResult($monitorConfig, $lastTime, $currentTime) { if (empty($monitorConfig)) { Ym_CommonTool::myoutput(FALSE, 'get monitor data error or empty!'); } //$this->plugins($monitorConfig); $model = new Model_Alarm_Monitorscript(); $serviceId = isset($monitorConfig['id']) ? $monitorConfig['id'] : ''; $log_app_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 = ''; //parse the params $alarm_arr = array(); $param_arr = explode("\n", $param); foreach ($param_arr as $v) { $arr = explode('=', $v); $key = isset($arr[0]) ? $arr[0] : 'error'; $alarm = isset($arr[1]) ? $arr[1] : 0; $alarm_arr[$key] = $alarm; } $cmd = '/reportapi/accesslog/NumberOfNode'; $return = Ym_CommonTool::phpCli($cmd, FALSE, TRUE); $data = json_decode($return, TRUE); foreach ($data['data']['series'] as $k => $v) { if (isset($alarm_arr['n']) and $k == $alarm_arr['n']) { continue; } if ($v <= $alarm_arr['c']) { $code = 2; $string .= $k . ' : <font color="red">' . $v . '</font><br/>'; continue; } if ($v <= $alarm_arr['w']) { $code = 1; $string .= $k . ' : <font color="#f89406">' . $v . '</font><br/>'; continue; } $string .= $k . ' : <font color="green">' . $v . '</font><br/>'; } $string .= 'warning:' . $alarm_arr['w'] . ' critical:' . $alarm_arr['c']; $thealarm = ' Id:' . $serviceId; $thealarm .= ' Time:' . date('Y/m/d H:i:s', $checkTime); $thealarm .= ' Code:' . $code; $thealarm .= ' IP:' . long2ip($ip); $thealarm .= ' App:' . $app; $thealarm .= ' Msg:"' . $string; Ym_Logger::debug(strip_tags($thealarm)); return array("time" => $currentTime, "code" => $code, "ip" => $ip, "app" => $app, "msg" => $string, "logid" => $logid, "log" => $log); }
/** * Yaf client command * * @author Xuexb<*****@*****.**> * @package xiaobo/sh * @since Version 1.0.1 @20140423 * @copyright Copyright (c) 2014, Yeahmobi, Inc. */ date_default_timezone_set('Asia/Shanghai'); define('YPP_APP', 'yeahmonitor'); define('YPP_APP_ROOT', YPP_DIR_APP . '/' . YPP_APP); define('YPP_APP_LIB', YPP_APP_ROOT . '/library'); // 声明loader Yaf_Loader::getInstance(YPP_APP_LIB, YPP_ROOT_PHPLIB); // 初始化配置和日志类 Ym_Config::init(); $logConf['logPath'] = YPP_DIR_LOG . '/app/' . YPP_APP; $logConf['logFile'] = YPP_APP; Ym_Logger::init($logConf); // 加载application.ini $app = new Yaf_Application(YPP_DIR_CONF . '/app/' . YPP_APP . '/application.ini'); $app->bootstrap(); $app->getDispatcher()->dispatch(new Yaf_Request_Simple()); //方法2:不试用带module的模式 //$controller = isset($argv[1]) ? $argv[1] : ''; //$action = isset($argv[2]) ? $argv[2] : ''; //if (!$controller || !$action) { // die('Please Use like this: /dianyi/app/ypp/bin/php yafClient.php controller action [argv]' . PHP_EOL); //} //$argv = isset($argv[3]) ? $argv[3] : ''; //$res = $app->execute(array('Controller_' . $controller, $action . 'Action'), $argv);
/** * 初始化APP的数据 * * @param string $app 启用的app的名称,如:test */ private static function initApp($app) { if (empty($app)) { return FALSE; } Ym_Timer::startRecord(); define('YPP_APP', $app); define('YPP_APP_ROOT', YPP_DIR_APP . '/' . YPP_APP); define('YPP_APP_LIB', YPP_APP_ROOT . '/library'); define('YPP_APP_LOG', YPP_DIR_LOG . '/' . YPP_APP); // 声明loader,加载APP类文件 Yaf_Loader::getInstance(YPP_APP_LIB); // 初始化配置 Ym_Config::init(); $env = Ym_Config::getAppItem('env:monitor.env'); if ($env) { define('YPP_APP_ENV', $env); } else { define('YPP_APP_ENV', 'dev'); } // 初始化日志 if (YPP_APP_ENV == 'pro') { $logConf['levels'] = array('debug' => 1, 'warning' => 4, 'error' => 5, 'fatal' => 6, 'alert' => 7, 'emergency' => 8); } $logConf['logPath'] = YPP_APP_LOG; $logConf['logFile'] = YPP_APP; Ym_Logger::init($logConf); //Ym_Logger::info('test'); // 加载application.ini self::$app = new Yaf_Application(YPP_DIR_CONF . '/app/' . YPP_APP . '/application.ini'); }
/** * * 检测脚本主要程序(只需要编写该方法即可) */ public function getCheckResult($monitorConfig, $lastTime, $currentTime) { if (empty($monitorConfig)) { Ym_CommonTool::myoutput(FALSE, 'get monitor data error or empty!'); } $serviceId = isset($monitorConfig['id']) ? $monitorConfig['id'] : ''; $log_app_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']) ? $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::debug('weblog.' . $service . ' checktime: ' . $checkTime . ' <= Last: ' . $lastTime . ', pass!*'); $checkTime = strtotime(date('Y-m-d H:i', $currentTime)); } $model = new Model_Alarm_Monitorscript(); $code = 0; $maxTime = 0; $msg = array(); $logid = 0; $log = ''; $string = ''; $color = 'green'; $num = 0; //parse the params $alarm_arr = array(); $param_arr = explode("\n", $param); foreach ($param_arr as $v) { $arr = explode('=', $v); $key = isset($arr[0]) ? $arr[0] : 'error'; $alarm = isset($arr[1]) ? $arr[1] : 0; $alarm_arr[$key] = $alarm; } $return = $model->checkLbsError($checkTime); if ($return['num'] and $return['num'] >= $alarm_arr['c']) { $code = 2; $color = 'red'; } elseif ($return['num'] and $return['num'] >= $alarm_arr['w'] and $return['num'] <= $alarm_arr['c']) { $code = 1; $color = '#f89406'; } $return['num'] == NULL ? $num = 0 : ($num = $return['num']); $string .= date('H:i', $checkTime) . ' = <font color="' . $color . '">' . $num . '</font> (status>=500)<br/>'; if ($code > 0) { $detail = $model->checkLbsErrorDetail($checkTime); if ($detail) { foreach ($detail as $v) { $string .= $v['host'] . ' ' . $v['path'] . ' ' . $v['status'] . ' ' . $v['server'] . ' = ' . $v['num'] . '<br/>'; } } } $string .= 'warning:' . $alarm_arr['w'] . ' critical:' . $alarm_arr['c']; $thealarm = ' Id:' . $serviceId; $thealarm .= ' Time:' . date('Y/m/d H:i:s', $checkTime); $thealarm .= ' Code:' . $code; $thealarm .= ' IP:' . long2ip($ip); $thealarm .= ' App:' . $app; $thealarm .= ' Msg:"' . $string; Ym_Logger::debug(strip_tags($thealarm)); return array("time" => $currentTime, "code" => $code, "ip" => $ip, "app" => $app, "msg" => $string, "logid" => $logid, "log" => $log); }
/** * * 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); }
<?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);
/** * * 检测脚本主要程序(只需要编写该方法即可) */ 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); }
/** * * 检测脚本主要程序(只需要编写该方法即可) * * 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); }
/** * * 检测脚本主要程序(只需要编写该方法即可) */ public function getCheckResult($monitorConfig, $lastTime, $currentTime) { if (empty($monitorConfig)) { Ym_CommonTool::myoutput(FALSE, 'get monitor data error or empty!'); } $serviceId = isset($monitorConfig['id']) ? $monitorConfig['id'] : ''; $log_app_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']) ? $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::debug('weblog.' . $service . ' checktime: ' . $checkTime . ' <= Last: ' . $lastTime . ', pass!*'); $checkTime = strtotime(date('Y-m-d H:i', $currentTime)); } $model = new Model_Alarm_Monitorscript(); $code = 0; $maxTime = 0; $msg = array(); $logid = 0; $log = ''; $string = ''; //parse the params $alarm_arr = array(); $param_arr = explode("\n", $param); foreach ($param_arr as $v) { $arr = explode('=', $v); $key = isset($arr[0]) ? $arr[0] : 'error'; $alarm = isset($arr[1]) ? $arr[1] : 0; $alarm_arr[$key] = $alarm; } $return1 = $model->checkLbsAccess($checkTime - 60); $return2 = $model->checkLbsAccess($checkTime); $num1 = $return1['num'] ? $return1['num'] : 0; $num2 = $return2['num'] ? $return2['num'] : 0; $currentdiff = 0; $go = 'fall'; $flug = '↓'; $color = 'green'; if ($num1 <= $num2) { $go = 'rise'; $flug = '↑'; } //上涨了 if ($num1 != 0) { $currentdiff = round(abs($num1 - $num2) / $num1 * 100, 2); } if (isset($alarm_arr['c']) and $currentdiff >= $alarm_arr['c']) { $code = 2; $color = 'red'; } elseif (isset($alarm_arr['w']) and $currentdiff >= $alarm_arr['w'] and $currentdiff <= $alarm_arr['c']) { $code = 1; $color = '#f89406'; } $string .= date('H:i', $checkTime - 60) . ' = ' . $num1 . '<br/>'; $string .= date('H:i', $checkTime) . ' = ' . $num2 . '<br/>'; $string .= $go . ' <font color="' . $color . '">' . $currentdiff . '% ' . $flug . '</font><br/>'; $string .= 'warning:' . $alarm_arr['w'] . '% critical:' . $alarm_arr['c'] . '%'; $thealarm = ' Id:' . $serviceId; $thealarm .= ' Time:' . date('Y/m/d H:i:s', $checkTime); $thealarm .= ' Code:' . $code; $thealarm .= ' IP:' . long2ip($ip); $thealarm .= ' App:' . $app; $thealarm .= ' Msg:"' . $string; Ym_Logger::debug(strip_tags($thealarm)); return array("time" => $currentTime, "code" => $code, "ip" => $ip, "app" => $app, "msg" => $string, "logid" => $logid, "log" => $log); }