Aggregate api of monitor at the backend

This commit is contained in:
zhuyj17 2018-10-14 21:34:46 +08:00
parent 69059c3fff
commit c1ba31a4b6
4 changed files with 32 additions and 31 deletions

View File

@ -579,7 +579,9 @@ def vnodes_monitor(user, beans, form, con_id, issue):
logger.info("handle request: monitor/vnodes") logger.info("handle request: monitor/vnodes")
res = {} res = {}
fetcher = monitor.Container_Fetcher(con_id) fetcher = monitor.Container_Fetcher(con_id)
if issue == 'cpu_use': if issue == 'info':
res = fetcher.get_info()
elif issue == 'cpu_use':
res['cpu_use'] = fetcher.get_cpu_use() res['cpu_use'] = fetcher.get_cpu_use()
elif issue == 'mem_use': elif issue == 'mem_use':
res['mem_use'] = fetcher.get_mem_use() res['mem_use'] = fetcher.get_mem_use()

View File

@ -111,6 +111,15 @@ class Container_Fetcher:
self.con_id = container_name self.con_id = container_name
return return
def get_info(self):
res = {}
res['cpu_use'] = self.get_cpu_use()
res['mem_use'] = self.get_mem_use()
res['disk_use'] = self.get_disk_use()
res['net_stats'] = self.get_net_stats()
res['basic_info'] = self.get_basic_info()
return res
def get_cpu_use(self): def get_cpu_use(self):
global monitor_vnodes global monitor_vnodes
try: try:

View File

@ -194,19 +194,6 @@ var node_name = $("#node_name").html();
var masterip = $("#masterip").html(); var masterip = $("#masterip").html();
var url = "http://" + host + "/monitor/" + masterip + "/vnodes/" + node_name; var url = "http://" + host + "/monitor/" + masterip + "/vnodes/" + node_name;
function processDiskData()
{
$.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)";
$("#con_disk").html(usedp+"%<br/>"+detail);
},"json");
}
setInterval(processDiskData,1000);
function num2human(data) function num2human(data)
{ {
units=['','K','M','G','T']; units=['','K','M','G','T'];
@ -222,9 +209,9 @@ function num2human(data)
return tempdata.toFixed(2) + units[4]; return tempdata.toFixed(2) + units[4];
} }
function processBasicInfo() function processInfo()
{ {
$.post(url+"/basic_info/",{},function(data){ $.post(url+"/info/",{},function(data){
basic_info = data.monitor.basic_info; basic_info = data.monitor.basic_info;
state = basic_info.State; state = basic_info.State;
if(state == 'STOPPED') if(state == 'STOPPED')
@ -246,8 +233,16 @@ function processBasicInfo()
$("#con_time").html(hour+"h "+min+"m "+secs+"s"); $("#con_time").html(hour+"h "+min+"m "+secs+"s");
$("#con_billing").html("<a target='_blank' title='How to figure out it?' href='https://unias.github.io/docklet/book/en/billing/billing.html'>"+basic_info.billing+" <img src='/static/img/bean.png' /></a>"); $("#con_billing").html("<a target='_blank' title='How to figure out it?' href='https://unias.github.io/docklet/book/en/billing/billing.html'>"+basic_info.billing+" <img src='/static/img/bean.png' /></a>");
$("#con_billingthishour").html("<a target='_blank' title='How to figure out it?' href='https://unias.github.io/docklet/book/en/billing/billing.html'>"+basic_info.billing_this_hour.total+" <img src='/static/img/bean.png' /></a>"); $("#con_billingthishour").html("<a target='_blank' title='How to figure out it?' href='https://unias.github.io/docklet/book/en/billing/billing.html'>"+basic_info.billing_this_hour.total+" <img src='/static/img/bean.png' /></a>");
},"json");
$.post(url+"/net_stats/",{},function(data){ //processDiskData
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)";
$("#con_disk").html(usedp+"%<br/>"+detail);
//processNetStats
var net_stats = data.monitor.net_stats; var net_stats = data.monitor.net_stats;
var in_rate = parseInt(net_stats.bytes_recv_per_sec); var in_rate = parseInt(net_stats.bytes_recv_per_sec);
var out_rate = parseInt(net_stats.bytes_sent_per_sec); var out_rate = parseInt(net_stats.bytes_sent_per_sec);
@ -280,7 +275,7 @@ function plot_net(host,monitorurl)
},"json"); },"json");
} }
setInterval(processBasicInfo,1000); setInterval(processInfo,1000);
plot_graph($("#mem-chart"),url + "/mem_use/",processMemData,getMemY); plot_graph($("#mem-chart"),url + "/mem_use/",processMemData,getMemY);
plot_graph($("#cpu-chart"),url + "/cpu_use/",processCpuData,getCpuY); plot_graph($("#cpu-chart"),url + "/cpu_use/",processCpuData,getCpuY);
plot_net(host, url + "/net_stats/"); plot_net(host, url + "/net_stats/");

View File

@ -314,16 +314,15 @@ function num2human(data)
function update(url,index) function update(url,index)
{ {
$.post(url+"/basic_info/",{},function(data){ $.post(url+"/info/",{},function(data){
$.post(url+"/disk_use/",{},function(data){ var diskuse = data.monitor.disk_use;
var diskuse = data.monitor.disk_use;
var usedp = diskuse.percent; var usedp = diskuse.percent;
var total = diskuse.total/1024.0/1024.0; var total = diskuse.total/1024.0/1024.0;
var used = diskuse.used/1024.0/1024.0; var used = diskuse.used/1024.0/1024.0;
var detail = "("+used.toFixed(2)+"MiB/"+total.toFixed(2)+"MiB)"; var detail = "("+used.toFixed(2)+"MiB/"+total.toFixed(2)+"MiB)";
$("#"+index+"_disk").html(usedp+"%<br/>"+detail); $("#"+index+"_disk").html(usedp+"%<br/>"+detail);
},"json");
var total = parseInt(data.monitor.basic_info.RunningTime); var total = parseInt(data.monitor.basic_info.RunningTime);
var hour = Math.floor(total / 3600); var hour = Math.floor(total / 3600);
var min = Math.floor(total % 3600 / 60); var min = Math.floor(total % 3600 / 60);
@ -364,7 +363,7 @@ function num2human(data)
$("#"+index+"_billing_disk_c").html(data.monitor.basic_info.c_disk) $("#"+index+"_billing_disk_c").html(data.monitor.basic_info.c_disk)
$("#"+index+"_billing_port_d").html(data.monitor.basic_info.d_port) $("#"+index+"_billing_port_d").html(data.monitor.basic_info.d_port)
var state = data.monitor.basic_info.State; var state = data.monitor.basic_info.State;
if(state == 'RUNNING') if(state == 'RUNNING')
{ {
var tmp = $("#"+index+"_state"); var tmp = $("#"+index+"_state");
@ -387,7 +386,6 @@ function num2human(data)
return; return;
} }
$.post(url+"/cpu_use/",{},function(data){
var usedp = data.monitor.cpu_use.usedp; var usedp = data.monitor.cpu_use.usedp;
var quota = data.monitor.cpu_use.quota.cpu; var quota = data.monitor.cpu_use.quota.cpu;
var quotaout = "("+quota; var quotaout = "("+quota;
@ -396,16 +394,13 @@ function num2human(data)
else else
quotaout += " Cores)"; quotaout += " Cores)";
$("#"+index+"_cpu").html((usedp/0.01).toFixed(2)+"%<br/>"+quotaout); $("#"+index+"_cpu").html((usedp/0.01).toFixed(2)+"%<br/>"+quotaout);
},"json");
$.post(url+"/mem_use/",{},function(data){
var usedp = data.monitor.mem_use.usedp; var usedp = data.monitor.mem_use.usedp;
var unit = data.monitor.mem_use.unit; var unit = data.monitor.mem_use.unit;
var quota = data.monitor.mem_use.quota.memory/1024.0; var quota = data.monitor.mem_use.quota.memory/1024.0;
var val = data.monitor.mem_use.val; var val = data.monitor.mem_use.val;
var out = "("+val+unit+"/"+quota.toFixed(2)+"MiB)"; var out = "("+val+unit+"/"+quota.toFixed(2)+"MiB)";
$("#"+index+"_mem").html((usedp/0.01).toFixed(2)+"%<br/>"+out); $("#"+index+"_mem").html((usedp/0.01).toFixed(2)+"%<br/>"+out);
},"json");
},"json"); },"json");
} }