Merge pull request #66 from FirmlyReality/diskusage

Diskusage
This commit is contained in:
leebaok 2016-04-23 18:46:08 +08:00
commit 4b634e6eb1
7 changed files with 74 additions and 32 deletions

View File

@ -342,6 +342,8 @@ class DockletHttpHandler(http.server.BaseHTTPRequestHandler):
res['cpu_use'] = fetcher.get_cpu_use(cmds[2])
elif cmds[3] == 'mem_use':
res['mem_use'] = fetcher.get_mem_use(cmds[2])
elif cmds[3] == 'disk_use':
res['disk_use'] = fetcher.get_disk_use(cmds[2])
elif cmds[3] == 'basic_info':
res['basic_info'] = fetcher.get_basic_info(cmds[2])
elif cmds[3] == 'owner':

View File

@ -63,11 +63,12 @@ class Container_Collector(threading.Thread):
self.mem_quota[container_name] = float(words[1].strip().strip("M"))*1000000/1024
elif key == "lxc.cgroup.cpu.cfs_quota_us":
tmp = int(words[1].strip())
if tmp == -1:
if tmp < 0:
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]}
logger.info(quota)
self.etcdser.setkey('/vnodes/%s/quota'%(container_name),quota)
else:
logger.error("Cant't find config file %s"%(confpath))
@ -81,7 +82,7 @@ class Container_Collector(threading.Thread):
cpu_usedp = 1
cpu_use['usedp'] = cpu_usedp
self.cpu_last[container_name] = cpu_val;
self.etcdser.setkey('vnodes/%s/cpu_use'%(container_name), cpu_use)
self.etcdser.setkey('/vnodes/%s/cpu_use'%(container_name), cpu_use)
mem_parts = re.split(' +',info['Memory use'])
mem_val = mem_parts[0].strip()
@ -139,6 +140,7 @@ class Collector(threading.Thread):
self.host = host
self.thread_stop = False
self.etcdser = etcdlib.Client(etcdaddr,"/%s/monitor/hosts/%s" % (cluster_name,host))
self.vetcdser = etcdlib.Client(etcdaddr,"/%s/monitor/vnodes" % (cluster_name))
self.interval = 1
self.test=test
return
@ -198,6 +200,10 @@ class Collector(threading.Thread):
diskval['used'] = usage.used
diskval['free'] = usage.free
diskval['percent'] = usage.percent
if(part.mountpoint.startswith('/opt/docklet/local/volume')):
names = re.split('/',part.mountpoint)
container = names[len(names)-1]
self.vetcdser.setkey('/%s/disk_use'%(container), diskval)
setval.append(diskval)
self.etcdser.setkey('/diskinfo', setval)
#print(output)
@ -268,6 +274,15 @@ class Container_Fetcher:
logger.warning(ans)
return res
def get_disk_use(self,container_name):
res = {}
[ret, ans] = self.etcdser.getkey('/%s/disk_use'%(container_name))
if ret == True :
res = dict(eval(ans))
else:
logger.warning(ans)
return res
def get_basic_info(self,container_name):
res = self.etcdser.getkey("/%s/basic_info"%(container_name))
if res[0] == False:

View File

@ -1,7 +1,6 @@
var mem_usedp = 0;
var cpu_usedp = 0;
function processMemData(data)
{
mem_usedp = data.monitor.mem_use.usedp;
@ -22,8 +21,12 @@ function processCpuData(data)
var val = data.monitor.cpu_use.val;
var unit = data.monitor.cpu_use.unit;
var quota = data.monitor.cpu_use.quota.cpu;
$("#con_cpu").html(val +" "+ unit);
$("#con_cpuquota").html(quota + " Cores");
var quotaout = "("+quota;
if(quota == 1)
quotaout += " Core)";
else
quotaout += " Cores)";
$("#con_cpu").html(val +" "+ unit+"<br/>"+quotaout);
}
function getCpuY()
{
@ -149,6 +152,7 @@ function plot_graph(container,url,processData,getY) {
}
var host = window.location.host;
var node_name = $("#node_name").html();
@ -156,3 +160,16 @@ 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){
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);

View File

@ -4,15 +4,15 @@ var total = 0;
var idle = 0;
var disk_usedp = 0;
var count = 0;
var MB = 1024;
var Ki = 1024;
function processMemData(data)
{
used = data.monitor.meminfo.used;
total = data.monitor.meminfo.total;
var used2 = ((data.monitor.meminfo.used)/MB).toFixed(2);
var total2 = ((data.monitor.meminfo.total)/MB).toFixed(2);
var free2 = ((data.monitor.meminfo.free)/MB).toFixed(2);
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);
@ -50,9 +50,9 @@ function processDiskData(data)
disk_usedp = vals[0].usedp;
for(var idx = 0; idx < vals.length; ++idx)
{
var used = (vals[idx].used/MB/MB).toFixed(2);
var total = (vals[idx].total/MB/MB).toFixed(2);
var free = (vals[idx].free/MB/MB).toFixed(2);
var used = (vals[idx].used/Ki/Ki).toFixed(2);
var total = (vals[idx].total/Ki/Ki).toFixed(2);
var free = (vals[idx].free/Ki/Ki).toFixed(2);
var usedp = (vals[idx].percent);
var name = "#disk_" + (idx+1) + "_";
$(name+"device").html(vals[idx].device);

View File

@ -126,7 +126,7 @@
<thead>
<tr>
<th colspan='4'>Cpu(%)</th>
<th colspan='3'>Memory(MB)</th>
<th colspan='3'>Memory(MiB)</th>
</tr>
<tr>
<th>user</th>
@ -175,9 +175,9 @@
</tr>
<tr>
<th>device</th>
<th>used(MB)</th>
<th>free(MB)</th>
<th>total(MB)</th>
<th>used(MiB)</th>
<th>free(MiB)</th>
<th>total(MiB)</th>
<th>used percent(%)</th>
</tr>
</thead>

View File

@ -82,10 +82,10 @@
<th>Node Name</th>
<th>IP Address</th>
<th>Status</th>
<th>Cpu used</th>
<th>Cpu quota</th>
<th>Mem used</th>
<th>Summary</th>
<th>Cpu Usage</th>
<th>Mem Usage</th>
<th>Disk Usage</th>
<th>Summary</th>
</tr>
</thead>
<tbody>
@ -101,9 +101,8 @@
<td><div id='{{cluster}}_{{ loop.index }}_state' class="label label-primary">Running</div></td>
{% endif %}
<td id='{{cluster}}_{{ loop.index }}_cpu'>--</td>
<td id='{{cluster}}_{{ loop.index }}_cpuquota'>--</td>
<td id='{{cluster}}_{{ loop.index }}_mem'>--</td>
<td id='{{cluster}}_{{ loop.index }}_disk'>--</td>
<td><a class="btn btn-info btn-xs" href='/vclusters/{{ cluster }}/{{ container['containername'] }}/'>Realtime</a></td>
</tr>
{% endfor %}
@ -143,7 +142,6 @@
$("#"+index+"_pid").html('--');
$("#"+index+"_ip").html('--');
$("#"+index+"_cpu").html('--');
$("#"+index+"_cpuquota").html('--');
$("#"+index+"_mem").html('--');
return;
}
@ -151,8 +149,12 @@
$.post(url+"/cpu_use",{},function(data){
var usedp = data.monitor.cpu_use.usedp;
var quota = data.monitor.cpu_use.quota.cpu;
$("#"+index+"_cpu").html((usedp/0.01).toFixed(2)+"%");
$("#"+index+"_cpuquota").html(quota+" Cores");
var quotaout = "("+quota;
if(quota == 1)
quotaout += " Core)";
else
quotaout += " Cores)";
$("#"+index+"_cpu").html((usedp/0.01).toFixed(2)+"%<br/>"+quotaout);
},"json");
$.post(url+"/mem_use",{},function(data){
@ -164,6 +166,14 @@
$("#"+index+"_mem").html((usedp/0.01).toFixed(2)+"%<br/>"+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+"%<br/>"+detail);
},"json");
},"json");
}

View File

@ -27,7 +27,7 @@
<div class="col-md-12">
<div class="box box-info">
<div class="box-header with-border">
<h3 class="box-title">Current Status</h3>
<h3 class="box-title">Current Status of {{ container['Name'] }}</h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
@ -39,17 +39,15 @@
<table class="table table-bordered">
<thead>
<tr>
<th>Name</th>
<th>State</th>
<th>IP Address</th>
<th>CPU Use</th>
<th>CPU Quota</th>
<th>Mem Use</th>
<th>CPU Usage</th>
<th>Mem Usage</th>
<th>Disk Usage</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ container['Name'] }}</td>
{% if container['State'] == 'STOPPED' %}
<td><div id='con_state' class="label label-danger">Stopped</div></td>
<td id='con_ip'>--</td>
@ -58,8 +56,8 @@
<td id='con_ip'>{{ container['IP'] }}</td>
{% endif %}
<td id='con_cpu'>--</td>
<td id='con_cpuquota'>--</td>
<td id='con_mem'>--</td>
<td id='con_disk'>--</td>
</tr>
</tbody>
</table>