add monitoring of gateways

This commit is contained in:
zhuyj17 2017-12-04 01:40:04 +08:00
parent e7684e955b
commit 0637d81304
4 changed files with 107 additions and 1 deletions

View File

@ -520,6 +520,10 @@ def user_quotainfo_monitor(user, beans, form, issue):
logger.info("handle request: monitor/user/createdvnodes/")
res = G_historymgr.getCreatedVNodes(user)
return json.dumps({'success':'true', 'createdvnodes':res})
elif issue == 'net_stats':
logger.info("handle request: monitor/user/net_stats/")
res = G_historymgr.get_user_net_stats(user)
return json.dumps({'success':'true', 'net_stats':res})
else:
return json.dumps({'success':'false', 'message':"Unspported Method!"})

View File

@ -73,6 +73,11 @@ workerinfo = {}
# has the second keys same as the third keys in monitor_vnodes.
workercinfo = {}
# store the network statistics of users' gateways on current Worker.
# key is username
# bytes_sent and bytes_recv are the second keys
gateways_stats = {}
# only use on worker
containerpids = []
pid2name = {}
@ -243,6 +248,11 @@ class Container_Collector(threading.Thread):
self.net_stats[key]['errout'] = int(raw_stats[key].errin)
self.net_stats[key]['dropin'] = int(raw_stats[key].dropout)
self.net_stats[key]['dropout'] = int(raw_stats[key].dropin)
else:
if key not in gateways_stats.keys():
gateways_stats[key] = {}
gateways_stats[key]['bytes_recv'] = int(raw_stats[key].bytes_sent)
gateways_stats[key]['bytes_sent'] = int(raw_stats[key].bytes_recv)
#logger.info(self.net_stats)
# the main function to collect monitoring data of a container
@ -542,10 +552,11 @@ class Collector(threading.Thread):
def workerFetchInfo(master_ip):
global workerinfo
global workercinfo
global gateways_stats
global G_masterip
# tell the worker the ip address of the master
G_masterip = master_ip
return str([workerinfo, workercinfo])
return str([workerinfo, workercinfo, gateways_stats])
# get owner name of a container
def get_owner(container_name):
@ -578,6 +589,7 @@ class Master_Collector(threading.Thread):
self.master_ip = master_ip
return
def run(self):
global monitor_hosts
global monitor_vnodes
@ -599,6 +611,11 @@ class Master_Collector(threading.Thread):
if not owner in monitor_vnodes.keys():
monitor_vnodes[owner] = {}
monitor_vnodes[owner][container] = info[1][container]
for user in info[2].keys():
if not user in monitor_vnodes.keys():
continue
else:
monitor_vnodes[user]['net_stats'] = info[2][user]
except Exception as err:
logger.warning(traceback.format_exc())
logger.warning(err)
@ -839,3 +856,14 @@ class History_Manager:
tmp = {"name":vnode.name,"billing":vnode.billing}
res.append(tmp)
return res
# get users' net_stats
def get_user_net_stats(self,owner):
global monitor_vnodes
try:
res = monitor_vnodes[owner]['net_stats']
except Exception as err:
logger.warning(traceback.format_exc())
logger.warning(err)
res = {}
return res

View File

@ -67,6 +67,41 @@
</div>
{% for master in allcontainers %}
<div class="row">
<div class="col-md-12">
<div class="box box-info">
<div class="box-header with-border">
<h3 class="box-title">Total Network Statistics @ {{master.split("@")[1]}}</h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
</button>
<button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
</div>
</div>
<div class="box-body table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th>Total Bytes Sent</th>
<th>Total Bytes Received</th>
<th>Total Bytes Transefer</th>
<th>Network Billings</th>
</tr>
</thead>
<tbody>
<tr>
<td id='{{master.split("@")[1]}}_bytes_sent'>--</td>
<td id='{{master.split("@")[1]}}_bytes_recv'>--</td>
<td id='{{master.split("@")[1]}}_bytes_total'>--</td>
<td id='{{master.split("@")[1]}}_net_billings'>--</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
{% for clustername, clusterinfo in allcontainers[master].items() %}
<div class="row">
<div class="col-md-12">
@ -133,6 +168,31 @@
{% block script_src %}
<script type='text/javascript'>
function num2human(data)
{
units=['','K','M','G','T'];
tempdata = data/1.0;
//return tempdata;
for(var i = 1; i < units.length; ++i)
{
if( tempdata / 1000.0 > 1)
tempdata = tempdata/1000.0;
else
return tempdata.toFixed(2) + units[i-1];
}
return tempdata.toFixed(2) + units[4];
}
function update_net_stats(url,index)
{
$.post(url,{},function(data){
var bytes_sent = parseInt(data.net_stats.bytes_sent);
var bytes_recv = parseInt(data.net_stats.bytes_recv);
$("#"+index+"_bytes_sent").html(num2human(bytes_sent)+"B");
$("#"+index+"_bytes_recv").html(num2human(bytes_recv)+"B");
$("#"+index+"_bytes_total").html(num2human(bytes_sent+bytes_recv)+"B");
//$("#"+index+"_net_billings").html(data.net_stats.billings);
},"json");
}
function update(url,index)
{
@ -207,6 +267,8 @@
//var url0 = "http://" + host + "/monitor/vnodes/";
{% for master in allcontainers %}
url = "http://" + host + "/monitor/" + '{{master.split("@")[0]}}' + "/user/net_stats/";
update_net_stats(url,'{{master.split("@")[1]}}')
{% for clustername, clusterinfo in allcontainers[master].items() %}
{% for container in clusterinfo['containers'] %}
//url = url0 + '{{ container['containername'] }}';

View File

@ -360,6 +360,18 @@ def monitor_request(comid,infotype,masterip):
logger.debug("monitor" + str(type(result)))
return json.dumps(result)
@app.route("/monitor/<masterip>/user/<issue>/", methods=['POST'])
@login_required
def monitor_user_request(issue,masterip):
data = {
"user": session['username']
}
path = "/monitor/user/" + str(issue) + "/"
logger.debug(path + "_____" + masterip)
result = dockletRequest.post(path, data, masterip)
logger.debug("monitor" + str(type(result)))
return json.dumps(result)
@app.route("/beans/application/", methods=['GET'])
@login_required
def beansapplication():