Commit 606496f7 authored by 吴贤德's avatar 吴贤德

监控———设备监控功能完善(增加负载状态判断,增加详情页显示)

parent 32332aaf
...@@ -21,10 +21,6 @@ class MonitorAction extends Action ...@@ -21,10 +21,6 @@ class MonitorAction extends Action
$limitCpu=0.9; $limitCpu=0.9;
$limitMem=0.9; $limitMem=0.9;
$redisConfig=C('RedisConfig');
$server = $redisConfig["server"];
$options = $redisConfig["options"];
$sql = "SELECT id,code,name,ip" $sql = "SELECT id,code,name,ip"
." FROM sh_hotel_device" ." FROM sh_hotel_device"
." WHERE status<2 " ." WHERE status<2 "
...@@ -38,7 +34,9 @@ class MonitorAction extends Action ...@@ -38,7 +34,9 @@ class MonitorAction extends Action
// var_dump($values);exit; // var_dump($values);exit;
$redisConfig=C('RedisConfig');
$server = $redisConfig["server"];
$options = $redisConfig["options"];
$redis = new Predis\Client($server,$options); $redis = new Predis\Client($server,$options);
$script_D = $this->makeLuaScript("LDR",$values); $script_D = $this->makeLuaScript("LDR",$values);
$script_S = $this->makeLuaScript("LSR",$values); $script_S = $this->makeLuaScript("LSR",$values);
...@@ -53,24 +51,34 @@ class MonitorAction extends Action ...@@ -53,24 +51,34 @@ class MonitorAction extends Action
foreach ($Devices as $k=>&$device){ foreach ($Devices as $k=>&$device){
$device["dinfo"]=json_decode($mDeviceData[$k]); //设备监控信息 $mDinfo=json_decode($mDeviceData[$k]); //设备监控信息
$device["sinfo"]=json_decode($mServiceData[$k]); //设备监控信息 $mSinfo=json_decode($mServiceData[$k]); //设备监控信息
$device["status"] = 0; //0正常,1服务汇报超时,2设备汇报超时,3,设备超负载,其他未知 $device["status"] = 0; //0正常,1服务汇报超时,2设备汇报超时,3,设备超负载,其他未知
$device["reason"] = "正常"; $device["reason"] = "正常";
$mTime = $device["sinfo"]->t; $mTime = $mSinfo->t;
if ($mTime+$limitRtimeout < time()){ if ($mTime+$limitRtimeout < time()){
$device["status"] = 1; //0正常,1服务汇报超时,2设备汇报超时,3,设备超负载,其他未知 $device["status"] = 1; //0正常,1服务汇报超时,2设备汇报超时,3,设备超负载,其他未知
$device["reason"] = "服务汇报超时"; $device["reason"] = "服务汇报超时";
} }
$device["lst"]= date( "Y-m-d H:i:s",$mTime) ; //汇报时间 $device["lst"]= date( "Y-m-d H:i:s",$mTime) ; //汇报时间
$mTime = $device["dinfo"]->t; $mTime = $mDinfo->t;
if ($mTime+$limitRtimeout < time()){ if ($mTime+$limitRtimeout < time()){
$device["status"] = 2; $device["status"] = 2;
$device["reason"] = "设备汇报超时"; $device["reason"] = "设备汇报超时";
} }
//判断负载 //判断负载
foreach ($mDinfo->o as $item){
if ($item[0]=="avg15" && $item[1]>=$limitCpu){
$device["status"]=3;
$device["reason"]="CPU超负载";
}
if ($item[0]=="mem" && $item[1]>=$limitMem){
$device["status"]=3;
$device["reason"]="内存超负载";
}
}
} }
...@@ -79,8 +87,8 @@ class MonitorAction extends Action ...@@ -79,8 +87,8 @@ class MonitorAction extends Action
} }
function makeLuaScript($key,$values){ function makeLuaScript($key,$value){
$script ="local d = redis.call(\"hmget\",\"$key\", $values)" $script ="local d = redis.call(\"hmget\",\"$key\", $value)"
." local r = {}" ." local r = {}"
." for k,v in ipairs(d)" ." for k,v in ipairs(d)"
." do" ." do"
...@@ -92,30 +100,56 @@ class MonitorAction extends Action ...@@ -92,30 +100,56 @@ class MonitorAction extends Action
return $script; return $script;
} }
function HttpPost($url,$param){ public function details(){
$id = $_GET["id"];
$this->assign('SYSTEM_INFO',C('SYSTEM_INFO'));
$ch = curl_init(); $limitRtimeout=30;
//如果$param是数组的话直接用 $limitCpu=0.9;
curl_setopt($ch, CURLOPT_URL, $url); $limitMem=0.9;
//如果$param是json格式的数据,则打开下面这个注释
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($param))
);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//如果用的协议是https则打开鞋面这个注释 $sql = "SELECT id,code,name,ip"
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); ." FROM sh_hotel_device"
// curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); ." WHERE id=$id;";
$data = curl_exec($ch); // echo $sql;
$Devices = D("")->query($sql);
$values="";
foreach ($Devices as $device){
$values.="\"".$device["code"]."\",";
}
$values=rtrim($values,",");
// var_dump($values);exit;
if (!empty($Devices)) {
$redisConfig = C('RedisConfig');
$server = $redisConfig["server"];
$options = $redisConfig["options"];
$redis = new Predis\Client($server, $options);
$script_D = $this->makeLuaScript("LDR", $values);
$script_S = $this->makeLuaScript("LSR", $values);
$mDeviceData = $redis->eval($script_D, 0);
$mServiceData = $redis->eval($script_S, 0);
// var_dump($mDeviceData);
// echo "<br/>";
// var_dump($mServiceData);
// exit;
// str_replace("world","Shanghai","Hello world!");
foreach ($Devices as $k => &$device) {
curl_close($ch); $device["设备监控信息"] = json_decode($mDeviceData[$k]); //设备监控信息
return $data; $device["服务监控信息"] = json_decode($mServiceData[$k]); //设备监控信息
} }
echo json_encode($Devices[0]);
}else{
$e["错误"] = "找不到该设备!";
echo json_encode($e);
}
}
} }
\ No newline at end of file
...@@ -13,4 +13,9 @@ class DeviceAction extends Action{ ...@@ -13,4 +13,9 @@ class DeviceAction extends Action{
$this->display(); $this->display();
} }
public function details(){
$this->assign("id",$_GET["id"]);
$this->display();
}
} }
\ No newline at end of file
<!DOCTYPE html>
<html lang="zh-CN"><head>
<title>设备监控信息详情</title>
<link href="__PUBLIC__/json_files/bootstrap.css" rel="stylesheet">
<link href="__PUBLIC__/font-awesome/css/font-awesome.css" rel="stylesheet">
<link href="__PUBLIC__/json_files/base.css" rel="stylesheet">
<style></style>
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<!-- Favicons -->
<style type="text/css">.json_key{ color: #92278f;font-weight:bold;}.json_null{color: #f1592a;font-weight:bold;}.json_string{ color: #3ab54a;font-weight:bold;}.json_number{ color: #25aae2;font-weight:bold;}.json_boolean{ color: #f98280;font-weight:bold;}.json_link{ color: #61D2D6;font-weight:bold;}.json_array_brackets{}</style></head>
<body style="over-flow:hidden;">
<main class="row-fluid" style="height:100%;">
<!--<div class="col-md-5" style="padding:0px;height:100%;">-->
<!--<div class="numberedtextarea-wrapper "><textarea id="json-src" placeholder="在此输入json字符串或XML字符串..." class="form-control common-font-size" style="height:100%;height: 87vh;min-height:520px;padding:10px 10px 10px 30px;border:0;border-right:solid 1px #E5EBEE;border-bottom:solid 1px #eee;border-radius:0;resize: none; outline:none;"></textarea><div class="numberedtextarea-line-numbers" style="padding-top: 10px; line-height: 18.9px; font-family: menlo, monospace, Tahoma, &quot;微软雅黑&quot;, &quot;幼圆&quot;; width: 30px;"><div class="numberedtextarea-number numberedtextarea-number-1" style="margin-bottom: 10px;">1</div></div></div>-->
<!--</div>-->
<div class="col-md-7" style="padding:0;position:relative;height:100%;">
<div id="right-box" class="common-font-size" style="width:100%;
border:solid 1px #f6f6f6;border-radius:0;resize: none;overflow-y:none;
outline:none;position:relative;padding-top:0px;">
<div id="line-num" style="background-color:#fafafa;padding:0px 8px;float:left;border-right:dashed 1px #E5EBEE;display:none;z-index:-1;color:#999;position:absolute;text-align:center;over-flow:hidden;"><div>1<div></div></div></div>
<div class="ro" id="json-target" style="padding:0px 25px;white-space: pre-line;word-wrap:break-word;"></div>
</div>
<!--<form id="form-save" method="POST"><input type="hidden" value="" id="txt-content" name="content"></form>-->
</div>
<br style="clear:both;">
</main>
<link href="__PUBLIC__/json_files/jquery.css" rel="stylesheet">
<script src="__PUBLIC__/json_files/jquery_002.js"></script>
<script src="__PUBLIC__/json_files/jquery_003.js"></script>
<div style="clear:both;"></div><div id="jquery-beauty-msg"></div>
<script src="__PUBLIC__/json_files/jquery_006.js"></script>
<script src="__PUBLIC__/json_files/jquery.js"></script>
<script src="__PUBLIC__/json_files/jquery_005.js"></script>
<script src="__PUBLIC__/json_files/json2.js"></script>
<script src="__PUBLIC__/json_files/jsonlint.js"></script>
<script src="__PUBLIC__/json_files/clipboard.js"></script>
<script src="__PUBLIC__/json_files/FileSaver.js"></script>
<script src="__PUBLIC__/json_files/bootstrap.js"></script>
<script src="__PUBLIC__/json_files/jquery_004.js"></script>
<script type="text/javascript">
function jsonformat(content) {
var result = '';
if (content!='') {
try{
// current_json = jsonlint.parse(content);
// current_json_str = JSON.stringify(current_json);
result = new JSONFormat(content,4).toString();
}catch(e){
result = '<span style="color: #f1592a;font-weight:bold;">' + e + '</span>';
current_json_str = result;
}
$('#json-target').html(result);
}else{
$('#json-target').html('');
}
}
$.ajax({
type: "POST",
url: "/api/monitor/details/id/{$id}",
data: {},
dataType: "text",
success: function (data) {
jsonformat(data);
},
error: function (err) {
alert("error");
}
});
</script>
</body></html>
\ No newline at end of file
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
</html> </html>
<script> <script>
function preview(id){ function preview(id){
pop(1000,600,true,'','','/Live/Channel/huikan/id/'+id); pop(600,520,true,'','','/Monitor/Device/details/id/'+id);
} }
$(function () { $(function () {
load(); load();
......
I hope you love Font Awesome. If you've found it useful, please do me a favor and check out my latest project,
Fort Awesome (https://fortawesome.com). It makes it easy to put the perfect icons on your website. Choose from our awesome,
comprehensive icon sets or copy and paste your own.
Please. Check it out.
-Dave Gandy
This diff is collapsed.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment