1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-25 15:45:23 +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['mem'] = None
if not cookies['cpu'] and not cookies['mem']:
datasets['cpu'] = [0]
datasets['mem'] = [0]
datasets['timer'] = [curent_time]
if not cookies['cpu'] or not cookies['mem']:
datasets['cpu'] = [0] * points
datasets['mem'] = [0] * points
datasets['timer'] = [0] * points
else:
datasets['cpu'] = eval(cookies['cpu'])
datasets['mem'] = eval(cookies['mem'])

View file

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

View file

@ -14,80 +14,89 @@
{% include 'errors_block.html' %}
<div class="row">
{% for user in users %}
<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-heading">
<h3 class="panel-title">
<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 class="panel-body">
<div class="col-xs-4 col-sm-4">
<p><strong>{% trans "Status:" %}</strong></p>
{% 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 %}
<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-heading">
<h3 class="panel-title">
<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 class="col-xs-4 col-sm-6">
{% if user.is_active %}
<p>{% trans "Active" %}</p>
{% else %}
<p>{% trans "Blocked" %}</p>
{% endif %}
<div class="panel-body">
<div class="col-xs-4 col-sm-4">
<p><strong>{% trans "Status:" %}</strong></p>
</div>
<div class="col-xs-4 col-sm-6">
{% if user.is_active %}
<p>{% trans "Active" %}</p>
{% else %}
<p>{% trans "Blocked" %}</p>
{% endif %}
</div>
</div>
</div>
</div>
</div>
<!-- Modal Edit -->
<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-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title">{% trans "Edit user info" %}</h4>
</div>
<div class="modal-body">
<form class="form-horizontal" method="post" role="form">{% csrf_token %}
<div class="form-group">
<label class="col-sm-4 control-label">{% trans "Name" %}</label>
<div class="col-sm-6">
<input type="hidden" name="user_id" value="{{ user.id }}">
<input type="text" name="name" class="form-control" value="{{ user.username }}" disabled>
<!-- Modal Edit -->
<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-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title">{% trans "Edit user info" %}</h4>
</div>
<div class="modal-body">
<form class="form-horizontal" method="post" role="form">{% csrf_token %}
<div class="form-group">
<label class="col-sm-4 control-label">{% trans "Name" %}</label>
<div class="col-sm-6">
<input type="hidden" name="user_id" value="{{ user.id }}">
<input type="text" name="name" class="form-control" value="{{ user.username }}" disabled>
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">{% trans "Password" %}</label>
<div class="col-sm-6">
<input type="password" name="user_pass" class="form-control" value="">
<div class="form-group">
<label class="col-sm-4 control-label">{% trans "Password" %}</label>
<div class="col-sm-6">
<input type="password" name="user_pass" class="form-control" value="">
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="pull-left btn btn-danger" name="delete">
{% trans "Delete" %}
</button>
{% if user.is_active %}
<button type="submit" class="pull-left btn btn-warning" name="block">
{% trans "Block" %}
</div>
<div class="modal-footer">
<button type="submit" class="pull-left btn btn-danger" name="delete">
{% trans "Delete" %}
</button>
{% else %}
<button type="submit" class="pull-left btn btn-success" name="unblock">
{% trans "Unblock" %}
{% if user.is_active %}
<button type="submit" class="pull-left btn btn-warning" name="block">
{% 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>
{% endif %}
<button type="button" class="btn btn-default" data-dismiss="modal">
{% trans "Close" %}
</button>
<button type="submit" class="btn btn-primary" name="edit">
{% trans "Edit" %}
</button>
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
{% endfor %}
<button type="submit" class="btn btn-primary" name="edit">
{% trans "Edit" %}
</button>
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
{% endfor %}
{% endif %}
</div>
{% endblock %}