Example #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;
 }
 /**
 * 
 * 检测脚本主要程序(只需要编写该方法即可)
 * 
 * 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);
 }
Example #3
0
 /**
  * 
  * 检测脚本主要程序(只需要编写该方法即可)
  */
 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);
 }
Example #4
0
 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');
 }
Example #5
0
 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');
 }
Example #6
0
 public function doMonitor($checkResult = array())
 {
     $enableNotify = $this->ifNotify();
     $updateR = $this->updateCheckResult($checkResult, $this->monitorConfig, $this->lastStatus, $enableNotify);
     $serviceId = isset($this->monitorConfig['id']) ? $this->monitorConfig['id'] : 0;
     if ($enableNotify) {
         $r = $this->doNotify($checkResult, $this->monitorConfig, $this->lastStatus);
     } else {
         Ym_CommonTool::myoutput(FALSE, 'ID: ' . $serviceId . ' DisableNotify ');
     }
 }
Example #7
0
 private function checkPostData()
 {
     $postData = $this->getRequest()->getPost();
     if (isset($postData['foo']) and $postData['foo'] == 'bar') {
         return $postData;
     }
     if (!isset($postData['email']) or !$postData['email']) {
         Ym_CommonTool::myoutput(FALSE, 'Param is error!');
     }
     return $postData;
 }
Example #8
0
 /**
  * 登陆
  *
  * @param $user
  */
 public function login($user)
 {
     // 存储用户信息到Session
     User_Session::setLoginSession($user);
     // 存储用户信息到Cookie
     User_Session::setLoginCookie($user);
     User_Session::setUserIdCookie($user['id']);
     $serviceUserOnline = new Model_User_Online();
     // 新增在线用户
     $userOnline = array('uid' => $user['id'], 'aliasName' => $user['aliasname'], 'fullName' => $user['fullname'], 'email' => $user['email'], 'ip' => Ym_CommonTool::get_ip());
     $serviceUserOnline->addUser($userOnline);
 }
Example #9
0
 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;
 }
Example #10
0
 public function add()
 {
     $this->configData = $this->getPostData($this->checkPostData());
     if (isset($this->configData['id']) and $this->configData['id']) {
         $result = $this->updateData();
     } else {
         $result = $this->insertData();
     }
     if ($result) {
         Ym_CommonTool::myoutput(1, 'Query is OK!', $result);
     } else {
         Ym_CommonTool::myoutput(0, 'Query is error!', array());
     }
     $this->display = 'none';
 }
Example #11
0
 public function modify()
 {
     $business = $this->_request->getPost('business');
     $status = $this->_request->getPost('status');
     $result = false;
     $result = setcookie("url_ids", $business, time() + 3600 * 24, '/');
     /*if ($status == 'close') {
           $result = $this->settingModel->closeBusiness($this->loginUser['id'], $business);
       } else if ($status == 'open') {
           $result = $this->settingModel->openBusiness($this->loginUser['id'], $business);
       }*/
     if ($result) {
         Ym_CommonTool::output($this, array('result' => 'success'), "json");
     } else {
         Ym_CommonTool::output($this, array('result' => 'failed'), "json");
     }
 }
Example #12
0
 public function updateCheckResult($checkResult, $monitorData, $lastStatus, $enableNotify)
 {
     if (empty($checkResult) or empty($monitorData)) {
         Ym_CommonTool::myoutput(FALSE, 'check result is empty or error!');
     }
     $status_change_time = 0;
     $next_check_time = 0;
     $data = array();
     $status_detail = '';
     $logid = '';
     $log = '';
     $id = $monitorData['id'] ? $monitorData['id'] : Ym_CommonTool::myoutput(FALSE, 'service id is empty or error!');
     $last_check_time = $checkResult['time'] ? $checkResult['time'] : time();
     $checkTime = $monitorData['monitor_check'] ? $monitorData['monitor_check'] : 1;
     $next_check_time = $last_check_time + $checkTime * 60;
     $status = isset($checkResult['code']) ? $checkResult['code'] : 3;
     if ($lastStatus != $status) {
         $status_change_time = $last_check_time;
     }
     if ($checkResult) {
         $data = array('last_check_time' => $last_check_time, 'next_check_time' => $next_check_time, 'status' => $status, 'status_detail' => $checkResult['msg']);
         if ($status_change_time) {
             $data['status_change_time'] = $status_change_time;
         }
         if ($enableNotify) {
             $data['last_notify_time'] = strtotime(date('Y-m-d H:i', time()));
         }
         //Ym_Logger::info('enableNotify:'.$enableNotify.'#'.$data['last_notify_time']);
         if ($checkResult['logid']) {
             $data['logid'] = rtrim($checkResult['logid'], '<br/>');
             $data['log'] = rtrim($checkResult['log'], '<br/>');
         } else {
             $data['logid'] = $data['log'] = '';
         }
         $where = "service_id=" . $id;
         $this->updatedata('monitor_alarm', $data, $where);
     } else {
         Ym_CommonTool::myoutput(FALSE, 'check result error!');
     }
 }
Example #13
0
 public function execute()
 {
     $this->getView()->setLayout($this->layout);
     // 是否get请求
     if ($this->getRequest()->isPost()) {
         $result = array('result' => 'success', 'text' => '登陆成功!');
         // 获取登陆数据
         $account = $this->getRequest()->getPost();
         // 获取登陆数长度
         $email_lenth = strlen(trim($account['email']));
         $password_length = strlen(trim($account['password']));
         // 格式检查
         if ($email_lenth == 0) {
             $result['result'] = 'error';
             $result['text'] = '邮箱地址格式错误!';
             Ym_CommonTool::output($this, $result, 'json');
         }
         if ($password_length < 6) {
             $result['result'] = 'error';
             $result['text'] = '密码长度不能小于6位字符!';
             Ym_CommonTool::output($this, $result, 'json');
         }
         // 查询用户信息是否存在
         $accountModel = new Model_User_Account();
         $user = $accountModel->getUser($account);
         // 如果用户信息不为空
         if (!empty($user)) {
             // 序列化用户信息到字符串
             $user['loginTime'] = time();
             $accountModel->login($user);
         } else {
             $result['result'] = 'error';
             $result['text'] = '用户名或密码不正确!';
         }
         Ym_CommonTool::output($this, $result, 'json');
     }
 }
Example #14
0
 /**
  * 
  * 检测脚本主要程序(只需要编写该方法即可)
  */
 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);
 }
Example #15
0
 /**
  * 
  * 检测脚本主要程序(只需要编写该方法即可)
  */
 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);
 }
 /**
  * 
  * 检测脚本主要程序(只需要编写该方法即可)
  */
 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);
 }
Example #17
0
 /**
  * 
  * 检测脚本主要程序(只需要编写该方法即可)
  */
 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);
 }