1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-26 16:15:25 +00:00

Fixed graphs timer

This commit is contained in:
Retspen 2015-03-25 11:59:22 +02:00
parent 1f68e8c5ed
commit 6da9676299
3 changed files with 109 additions and 94 deletions

View file

@ -195,10 +195,10 @@ def compute_graph(request, compute_id):
cookies['cpu'] = None cookies['cpu'] = None
cookies['mem'] = None cookies['mem'] = None
if not cookies['cpu'] and not cookies['mem']: if not cookies['cpu'] or not cookies['mem']:
datasets['cpu'] = [0] datasets['cpu'] = [0] * points
datasets['mem'] = [0] datasets['mem'] = [0] * points
datasets['timer'] = [curent_time] datasets['timer'] = [0] * points
else: else:
datasets['cpu'] = eval(cookies['cpu']) datasets['cpu'] = eval(cookies['cpu'])
datasets['mem'] = eval(cookies['mem']) datasets['mem'] = eval(cookies['mem'])

View file

@ -448,18 +448,14 @@ def inst_graph(request, compute_id, vname):
return HttpResponseRedirect(reverse('login')) return HttpResponseRedirect(reverse('login'))
datasets = {} datasets = {}
datasets_rd = []
datasets_wr = []
json_blk = [] json_blk = []
cookie_blk = {} datasets_blk = {}
datasets_rx = []
datasets_tx = []
json_net = [] json_net = []
cookie_net = {} datasets_net = {}
cookies = {}
points = 5 points = 5
curent_time = time.strftime("%H:%M:%S") curent_time = time.strftime("%H:%M:%S")
compute = Compute.objects.get(id=compute_id) compute = Compute.objects.get(id=compute_id)
cookies = request.COOKIES
response = HttpResponse() response = HttpResponse()
response['Content-Type'] = "text/javascript" response['Content-Type'] = "text/javascript"
@ -479,12 +475,22 @@ def inst_graph(request, compute_id, vname):
net_usage = conn.net_usage() net_usage = conn.net_usage()
conn.close() conn.close()
if cookies.get('cpu') == '{}' or not cookies.get('cpu') or not cpu_usage: try:
datasets['cpu'] = [0] cookies['cpu'] = request.COOKIES['cpu']
datasets['timer'] = [curent_time] cookies['blk'] = request.COOKIES['blk']
cookies['net'] = request.COOKIES['net']
cookies['timer'] = request.COOKIES['timer']
except KeyError:
cookies['cpu'] = None
cookies['blk'] = None
cookies['net'] = None
if not cookies['cpu']:
datasets['cpu'] = [0] * points
datasets['timer'] = [0] * points
else: else:
datasets['cpu'] = eval(cookies.get('cpu')) datasets['cpu'] = eval(cookies['cpu'])
datasets['timer'] = eval(cookies.get('timer')) datasets['timer'] = eval(cookies['timer'])
datasets['timer'].append(curent_time) datasets['timer'].append(curent_time)
datasets['cpu'].append(int(cpu_usage['cpu'])) datasets['cpu'].append(int(cpu_usage['cpu']))
@ -493,11 +499,11 @@ def inst_graph(request, compute_id, vname):
datasets['cpu'] = check_points(datasets['cpu']) datasets['cpu'] = check_points(datasets['cpu'])
for blk in blk_usage: for blk in blk_usage:
if cookies.get('blk') == '{}' or not cookies.get('blk') or not blk_usage: if not cookies['blk']:
datasets_wr.append(0) datasets_wr = [0] * points
datasets_rd.append(0) datasets_rd = [0] * points
else: else:
datasets['blk'] = eval(cookies.get('blk')) datasets['blk'] = eval(cookies['blk'])
datasets_rd = datasets['blk'][blk['dev']][0] datasets_rd = datasets['blk'][blk['dev']][0]
datasets_wr = datasets['blk'][blk['dev']][1] datasets_wr = datasets['blk'][blk['dev']][1]
@ -508,14 +514,14 @@ def inst_graph(request, compute_id, vname):
datasets_wr = check_points(datasets_wr) datasets_wr = check_points(datasets_wr)
json_blk.append({'dev': blk['dev'], 'data': [datasets_rd, datasets_wr]}) json_blk.append({'dev': blk['dev'], 'data': [datasets_rd, datasets_wr]})
cookie_blk[blk['dev']] = [datasets_rd, datasets_wr] datasets_blk[blk['dev']] = [datasets_rd, datasets_wr]
for net in net_usage: for net in net_usage:
if cookies.get('net') == '{}' or not cookies.get('net') or not net_usage: if not cookies['net']:
datasets_rx.append(0) datasets_rx = [0] * points
datasets_tx.append(0) datasets_tx = [0] * points
else: else:
datasets['net'] = eval(cookies.get('net')) datasets['net'] = eval(cookies['net'])
datasets_rx = datasets['net'][net['dev']][0] datasets_rx = datasets['net'][net['dev']][0]
datasets_tx = datasets['net'][net['dev']][1] datasets_tx = datasets['net'][net['dev']][1]
@ -526,14 +532,14 @@ def inst_graph(request, compute_id, vname):
datasets_tx = check_points(datasets_tx) datasets_tx = check_points(datasets_tx)
json_net.append({'dev': net['dev'], 'data': [datasets_rx, datasets_tx]}) json_net.append({'dev': net['dev'], 'data': [datasets_rx, datasets_tx]})
cookie_net[net['dev']] = [datasets_rx, datasets_tx] datasets_net[net['dev']] = [datasets_rx, datasets_tx]
data = json.dumps({'cpudata': datasets['cpu'], 'blkdata': json_blk, 'netdata': json_net, 'timeline': datasets['timer']}) data = json.dumps({'cpudata': datasets['cpu'], 'blkdata': json_blk, 'netdata': json_net, 'timeline': datasets['timer']})
response.cookies['cpu'] = datasets['cpu'] response.cookies['cpu'] = datasets['cpu']
response.cookies['timer'] = datasets['timer'] response.cookies['timer'] = datasets['timer']
response.cookies['blk'] = cookie_blk response.cookies['blk'] = datasets_blk
response.cookies['net'] = cookie_net response.cookies['net'] = datasets_net
except libvirtError: except libvirtError:
data = json.dumps({'error': 'Error 500'}) data = json.dumps({'error': 'Error 500'})

View file

@ -14,6 +14,14 @@
{% include 'errors_block.html' %} {% include 'errors_block.html' %}
<div class="row"> <div class="row">
{% if not users %}
<div class="col-lg-12">
<div class="alert alert-warning alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<i class="fa fa-exclamation-triangle"></i> <strong>{% trans "Warning:" %}</strong> {% trans "You don't have any User" %}
</div>
</div>
{% else %}
{% for user in users %} {% for user in users %}
<div id="{{ user.username }}" class="col-xs-12 col-sm-4"> <div id="{{ user.username }}" class="col-xs-12 col-sm-4">
<div class="panel {% if user.is_active %}panel-success{% else %}panel-danger{% endif %} panel-data"> <div class="panel {% if user.is_active %}panel-success{% else %}panel-danger{% endif %} panel-data">
@ -89,5 +97,6 @@
</div><!-- /.modal-dialog --> </div><!-- /.modal-dialog -->
</div><!-- /.modal --> </div><!-- /.modal -->
{% endfor %} {% endfor %}
{% endif %}
</div> </div>
{% endblock %} {% endblock %}