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,80 +14,89 @@
{% include 'errors_block.html' %} {% include 'errors_block.html' %}
<div class="row"> <div class="row">
{% for user in users %} {% if not users %}
<div id="{{ user.username }}" class="col-xs-12 col-sm-4"> <div class="col-lg-12">
<div class="panel {% if user.is_active %}panel-success{% else %}panel-danger{% endif %} panel-data"> <div class="alert alert-warning alert-dismissable">
<div class="panel-heading"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h3 class="panel-title"> <i class="fa fa-exclamation-triangle"></i> <strong>{% trans "Warning:" %}</strong> {% trans "You don't have any User" %}
<a href="{% url 'account' user.id %}"><strong>{{ user.username }}</strong></a> </div>
<a data-toggle="modal" href="#editUser{{ user.id }}" class="pull-right" title="{% trans "Edit" %}"> </div>
<span class="glyphicon glyphicon-cog"></span> {% else %}
</a> {% for user in users %}
</h3> <div id="{{ user.username }}" class="col-xs-12 col-sm-4">
</div> <div class="panel {% if user.is_active %}panel-success{% else %}panel-danger{% endif %} panel-data">
<div class="panel-body"> <div class="panel-heading">
<div class="col-xs-4 col-sm-4"> <h3 class="panel-title">
<p><strong>{% trans "Status:" %}</strong></p> <a href="{% url 'account' user.id %}"><strong>{{ user.username }}</strong></a>
<a data-toggle="modal" href="#editUser{{ user.id }}" class="pull-right" title="{% trans "Edit" %}">
<span class="glyphicon glyphicon-cog"></span>
</a>
</h3>
</div> </div>
<div class="col-xs-4 col-sm-6"> <div class="panel-body">
{% if user.is_active %} <div class="col-xs-4 col-sm-4">
<p>{% trans "Active" %}</p> <p><strong>{% trans "Status:" %}</strong></p>
{% else %} </div>
<p>{% trans "Blocked" %}</p> <div class="col-xs-4 col-sm-6">
{% endif %} {% if user.is_active %}
<p>{% trans "Active" %}</p>
{% else %}
<p>{% trans "Blocked" %}</p>
{% endif %}
</div>
</div> </div>
</div> </div>
</div> </div>
</div>
<!-- Modal Edit --> <!-- Modal Edit -->
<div class="modal fade" id="editUser{{ user.id }}" tabindex="-1" role="dialog" aria-labelledby="editUserLabel" aria-hidden="true"> <div class="modal fade" id="editUser{{ user.id }}" tabindex="-1" role="dialog" aria-labelledby="editUserLabel" aria-hidden="true">
<div class="modal-dialog"> <div class="modal-dialog">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title">{% trans "Edit user info" %}</h4> <h4 class="modal-title">{% trans "Edit user info" %}</h4>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<form class="form-horizontal" method="post" role="form">{% csrf_token %} <form class="form-horizontal" method="post" role="form">{% csrf_token %}
<div class="form-group"> <div class="form-group">
<label class="col-sm-4 control-label">{% trans "Name" %}</label> <label class="col-sm-4 control-label">{% trans "Name" %}</label>
<div class="col-sm-6"> <div class="col-sm-6">
<input type="hidden" name="user_id" value="{{ user.id }}"> <input type="hidden" name="user_id" value="{{ user.id }}">
<input type="text" name="name" class="form-control" value="{{ user.username }}" disabled> <input type="text" name="name" class="form-control" value="{{ user.username }}" disabled>
</div>
</div> </div>
</div> <div class="form-group">
<div class="form-group"> <label class="col-sm-4 control-label">{% trans "Password" %}</label>
<label class="col-sm-4 control-label">{% trans "Password" %}</label> <div class="col-sm-6">
<div class="col-sm-6"> <input type="password" name="user_pass" class="form-control" value="">
<input type="password" name="user_pass" class="form-control" value=""> </div>
</div> </div>
</div> </div>
</div> <div class="modal-footer">
<div class="modal-footer"> <button type="submit" class="pull-left btn btn-danger" name="delete">
<button type="submit" class="pull-left btn btn-danger" name="delete"> {% trans "Delete" %}
{% trans "Delete" %}
</button>
{% if user.is_active %}
<button type="submit" class="pull-left btn btn-warning" name="block">
{% trans "Block" %}
</button> </button>
{% else %} {% if user.is_active %}
<button type="submit" class="pull-left btn btn-success" name="unblock"> <button type="submit" class="pull-left btn btn-warning" name="block">
{% trans "Unblock" %} {% trans "Block" %}
</button>
{% else %}
<button type="submit" class="pull-left btn btn-success" name="unblock">
{% trans "Unblock" %}
</button>
{% endif %}
<button type="button" class="btn btn-default" data-dismiss="modal">
{% trans "Close" %}
</button> </button>
{% endif %} <button type="submit" class="btn btn-primary" name="edit">
<button type="button" class="btn btn-default" data-dismiss="modal"> {% trans "Edit" %}
{% trans "Close" %} </button>
</button> </form>
<button type="submit" class="btn btn-primary" name="edit"> </div>
{% trans "Edit" %} </div><!-- /.modal-content -->
</button> </div><!-- /.modal-dialog -->
</form> </div><!-- /.modal -->
</div> {% endfor %}
</div><!-- /.modal-content --> {% endif %}
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
{% endfor %}
</div> </div>
{% endblock %} {% endblock %}