From 02cbccdd153fb1fd38fbebfdbd8b84319495f31f Mon Sep 17 00:00:00 2001 From: zhuyj17 Date: Mon, 11 Apr 2016 12:17:06 +0800 Subject: [PATCH] Set quota in etcd and read from etcd for each container. --- src/httprest.py | 3 +-- src/monitor.py | 12 ++++++++++++ web/static/js/plot_monitor.js | 9 ++++----- web/templates/monitor/status.html | 9 ++++----- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/httprest.py b/src/httprest.py index 56d6898..efded1b 100755 --- a/src/httprest.py +++ b/src/httprest.py @@ -342,8 +342,7 @@ class DockletHttpHandler(http.server.BaseHTTPRequestHandler): res['mem_use'] = fetcher.get_mem_use(cmds[2]) elif cmds[3] == 'basic_info': res['basic_info'] = fetcher.get_basic_info(cmds[2]) - user_info = G_usermgr.selfQuery(cur_user = cur_user) - self.response(200, {'success':'true', 'monitor':res, 'groupinfo':user_info['data']['groupinfo']}) + self.response(200, {'success':'true', 'monitor':res}) elif cmds[1] == 'user': if not user == 'root': self.response(400, {'success':'false', 'message':'Root Required'}) diff --git a/src/monitor.py b/src/monitor.py index c437425..5fb05bc 100755 --- a/src/monitor.py +++ b/src/monitor.py @@ -67,6 +67,8 @@ class Container_Collector(threading.Thread): self.cpu_quota[container_name] = self.cores_num else: self.cpu_quota[container_name] = tmp/100000.0 + quota = {'cpu':self.cpu_quota[container_name],'memory':self.mem_quota[container_name]} + self.etcdser.setkey('/vnodes/%s/quota'%(container_name),quota) else: logger.error("Cant't find config file %s"%(confpath)) return False @@ -241,6 +243,11 @@ class Container_Fetcher: [ret, ans] = self.etcdser.getkey('/%s/cpu_use'%(container_name)) if ret == True : res = dict(eval(ans)) + [ret,quota] = self.etcdser.getkey('/%s/quota'%(container_name)) + if ret == False: + res['quota'] = {'cpu':0} + logger.warning(quota) + res['quota'] = dict(eval(quota)) return res else: logger.warning(ans) @@ -251,6 +258,11 @@ class Container_Fetcher: [ret, ans] = self.etcdser.getkey('/%s/mem_use'%(container_name)) if ret == True : res = dict(eval(ans)) + [ret,quota] = self.etcdser.getkey('/%s/quota'%(container_name)) + if ret == False: + res['quota'] = {'memory':0} + logger.warning(quota) + res['quota'] = dict(eval(quota)) return res else: logger.warning(ans) diff --git a/web/static/js/plot_monitor.js b/web/static/js/plot_monitor.js index c3729b1..ae20fed 100755 --- a/web/static/js/plot_monitor.js +++ b/web/static/js/plot_monitor.js @@ -7,9 +7,9 @@ function processMemData(data) mem_usedp = data.monitor.mem_use.usedp; var usedp = data.monitor.mem_use.usedp; var unit = data.monitor.mem_use.unit; - var quota = data.groupinfo.memory; + var quota = data.monitor.mem_use.quota.memory/1024.0; var val = data.monitor.mem_use.val; - var out = "("+val+unit+"/"+quota+"MB)"; + var out = "("+val+unit+"/"+quota.toFixed(2)+"MiB)"; $("#con_mem").html((usedp/0.01).toFixed(2)+"%
"+out); } function getMemY() @@ -21,10 +21,9 @@ function processCpuData(data) cpu_usedp = data.monitor.cpu_use.usedp; var val = data.monitor.cpu_use.val; var unit = data.monitor.cpu_use.unit; - var quota = data.groupinfo.cpu; - quota = quota/1000.0; + var quota = data.monitor.cpu_use.quota.cpu; $("#con_cpu").html(val +" "+ unit); - $("#con_cpuquota").html(quota.toFixed(2)+"% Cores"); + $("#con_cpuquota").html(quota + " Cores"); } function getCpuY() { diff --git a/web/templates/monitor/status.html b/web/templates/monitor/status.html index 826fa6e..ec85a72 100644 --- a/web/templates/monitor/status.html +++ b/web/templates/monitor/status.html @@ -106,18 +106,17 @@ $.post(url+"/cpu_use",{},function(data){ var usedp = data.monitor.cpu_use.usedp; - var quota = data.groupinfo.cpu; - quota = quota/100000.0; + var quota = data.monitor.cpu_use.quota.cpu; $("#"+index+"_cpu").html((usedp/0.01).toFixed(2)+"%"); - $("#"+index+"_cpuquota").html((quota*100).toFixed(2)+"% Cores"); + $("#"+index+"_cpuquota").html(quota+" Cores"); },"json"); $.post(url+"/mem_use",{},function(data){ var usedp = data.monitor.mem_use.usedp; var unit = data.monitor.mem_use.unit; - var quota = data.groupinfo.memory; + var quota = data.monitor.mem_use.quota.memory/1024.0; var val = data.monitor.mem_use.val; - var out = "("+val+unit+"/"+quota+"MB)"; + var out = "("+val+unit+"/"+quota.toFixed(2)+"MiB)"; $("#"+index+"_mem").html((usedp/0.01).toFixed(2)+"%
"+out); },"json");