From cd43e0889d030fa89e728522b85054db3452f837 Mon Sep 17 00:00:00 2001 From: zhuyj17 Date: Sat, 21 May 2016 15:28:10 +0800 Subject: [PATCH 1/3] Let the rpc server not to log the requests. --- src/worker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/worker.py b/src/worker.py index 00ddef0..9e878c3 100755 --- a/src/worker.py +++ b/src/worker.py @@ -117,7 +117,7 @@ class Worker(object): logger.info ("initialize rpcserver %s:%d" % (self.addr, int(self.port))) # logRequests=False : not print rpc log #self.rpcserver = xmlrpc.server.SimpleXMLRPCServer((self.addr, self.port), logRequests=False) - self.rpcserver = ThreadXMLRPCServer((self.addr, int(self.port)), allow_none=True) + self.rpcserver = ThreadXMLRPCServer((self.addr, int(self.port)), allow_none=True, logRequests=False) self.rpcserver.register_introspection_functions() self.rpcserver.register_instance(Containers) self.rpcserver.register_function(monitor.workerFetchInfo) From ec5861d67cc58f58bc6c52f1c0684542176d918b Mon Sep 17 00:00:00 2001 From: zhuyj17 Date: Sat, 21 May 2016 15:48:37 +0800 Subject: [PATCH 2/3] When container is stopped, running time and disk usage will also be displayed. --- src/monitor.py | 3 +++ web/templates/monitor/status.html | 20 +++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/monitor.py b/src/monitor.py index b2e1c7d..3e5b275 100755 --- a/src/monitor.py +++ b/src/monitor.py @@ -65,6 +65,9 @@ class Container_Collector(threading.Thread): #if basic_exist: # logger.info(workercinfo[container_name]['basic_info']) if(info['State'] == 'STOPPED'): + if not 'RunningTime' in basic_info.keys(): + basic_info['RunningTime'] = 0 + basic_info['LastTime'] = 0 workercinfo[container_name]['basic_info'] = basic_info logger.info(basic_info) return False diff --git a/web/templates/monitor/status.html b/web/templates/monitor/status.html index f674ce6..b434945 100644 --- a/web/templates/monitor/status.html +++ b/web/templates/monitor/status.html @@ -125,6 +125,17 @@ { $.post(url+"/basic_info/",{},function(data){ + + $.post(url+"/disk_use/",{},function(data){ + var diskuse = data.monitor.disk_use; + var usedp = diskuse.percent; + var total = diskuse.total/1024.0/1024.0; + var used = diskuse.used/1024.0/1024.0; + var detail = "("+used.toFixed(2)+"MiB/"+total.toFixed(2)+"MiB)"; + $("#"+index+"_disk").html(usedp+"%
"+detail); + },"json"); + $("#"+index+"_time").html(data.monitor.basic_info.RunningTime+"s") + var state = data.monitor.basic_info.State; if(state == 'RUNNING') { @@ -147,7 +158,6 @@ $("#"+index+"_mem").html('--'); return; } - $("#"+index+"_time").html(data.monitor.basic_info.RunningTime+"s") $.post(url+"/cpu_use/",{},function(data){ var usedp = data.monitor.cpu_use.usedp; @@ -169,14 +179,6 @@ $("#"+index+"_mem").html((usedp/0.01).toFixed(2)+"%
"+out); },"json"); - $.post(url+"/disk_use/",{},function(data){ - var diskuse = data.monitor.disk_use; - var usedp = diskuse.percent; - var total = diskuse.total/1024.0/1024.0; - var used = diskuse.used/1024.0/1024.0; - var detail = "("+used.toFixed(2)+"MiB/"+total.toFixed(2)+"MiB)"; - $("#"+index+"_disk").html(usedp+"%
"+detail); - },"json"); },"json"); } From 117cb718fff65c6e5164139f95bd73d3953df8be Mon Sep 17 00:00:00 2001 From: zhuyj17 Date: Sat, 21 May 2016 16:13:03 +0800 Subject: [PATCH 3/3] When worker is stopped, hosts realtime page will stop to fetch cpu and memory information. --- web/static/js/plot_monitor.js | 5 +-- web/static/js/plot_monitorReal.js | 68 +++++++++++++++++++++++-------- 2 files changed, 53 insertions(+), 20 deletions(-) diff --git a/web/static/js/plot_monitor.js b/web/static/js/plot_monitor.js index d72f10a..0dd128c 100755 --- a/web/static/js/plot_monitor.js +++ b/web/static/js/plot_monitor.js @@ -175,9 +175,6 @@ var host = window.location.host; var node_name = $("#node_name").html(); var url = "http://" + host + "/monitor/vnodes/" + node_name; -plot_graph($("#mem-chart"),url + "/mem_use/",processMemData,getMemY); -plot_graph($("#cpu-chart"),url + "/cpu_use/",processCpuData,getCpuY); - function processDiskData() { $.post(url+"/disk_use/",{},function(data){ @@ -212,3 +209,5 @@ function processBasicInfo() },"json"); } setInterval(processBasicInfo,1000); +plot_graph($("#mem-chart"),url + "/mem_use/",processMemData,getMemY); +plot_graph($("#cpu-chart"),url + "/cpu_use/",processCpuData,getCpuY); diff --git a/web/static/js/plot_monitorReal.js b/web/static/js/plot_monitorReal.js index b85cc6a..58fbde1 100755 --- a/web/static/js/plot_monitorReal.js +++ b/web/static/js/plot_monitorReal.js @@ -5,17 +5,28 @@ var idle = 0; var disk_usedp = 0; var count = 0; var Ki = 1024; +var is_running = true; function processMemData(data) { - used = data.monitor.meminfo.used; - total = data.monitor.meminfo.total; - var used2 = ((data.monitor.meminfo.used)/Ki).toFixed(2); - var total2 = ((data.monitor.meminfo.total)/Ki).toFixed(2); - var free2 = ((data.monitor.meminfo.free)/Ki).toFixed(2); - $("#mem_used").html(used2); - $("#mem_total").html(total2); - $("#mem_free").html(free2); + if(is_running) + { + used = data.monitor.meminfo.used; + total = data.monitor.meminfo.total; + var used2 = ((data.monitor.meminfo.used)/Ki).toFixed(2); + var total2 = ((data.monitor.meminfo.total)/Ki).toFixed(2); + var free2 = ((data.monitor.meminfo.free)/Ki).toFixed(2); + $("#mem_used").html(used2); + $("#mem_total").html(total2); + $("#mem_free").html(free2); + } + else + { + total = 0; + $("#mem_used").html("--"); + $("#mem_total").html("--"); + $("#mem_free").html("--"); + } } function getMemY() { @@ -26,14 +37,25 @@ function getMemY() } function processCpuData(data) { - idle = data.monitor.cpuinfo.idle; - var us = data.monitor.cpuinfo.user; - var sy = data.monitor.cpuinfo.system; - var wa = data.monitor.cpuinfo.iowait; - $("#cpu_user").html(us); - $("#cpu_system").html(sy); - $("#cpu_iowait").html(wa); - $("#cpu_idle").html(idle); + if(is_running) + { + idle = data.monitor.cpuinfo.idle; + var us = data.monitor.cpuinfo.user; + var sy = data.monitor.cpuinfo.system; + var wa = data.monitor.cpuinfo.iowait; + $("#cpu_user").html(us); + $("#cpu_system").html(sy); + $("#cpu_iowait").html(wa); + $("#cpu_idle").html(idle); + } + else + { + idle = 100; + $("#cpu_user").html("--"); + $("#cpu_system").html("--"); + $("#cpu_iowait").html("--"); + $("#cpu_idle").html("--"); + } } function getCpuY() { @@ -190,8 +212,20 @@ var host = window.location.host; var com_ip = $("#com_ip").html(); var url = "http://" + host + "/monitor/hosts/"+com_ip; +function processStatus() +{ + $.post(url+"/status/",{},function(data){ + var state = data.monitor.status; + if(state == 'RUNNING') + is_running = true; + else + is_running = false; + },"json"); +} +setInterval(processStatus,1000); + plot_graph($("#mem-chart"), url + "/meminfo/",processMemData,getMemY); plot_graph($("#cpu-chart"), url + "/cpuinfo/",processCpuData,getCpuY); //plot_graph($("#disk-chart"), url + "/diskinfo",processDiskData,getDiskY); -$.post(url+"/diskinfo/",{user:"root",key:"unias"},processDiskData,"json"); +$.post(url+"/diskinfo/",{},processDiskData,"json");