mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-25 15:45:23 +00:00
Fixed graphs on instance page
This commit is contained in:
parent
4a17f08740
commit
8d18d40295
2 changed files with 32 additions and 23 deletions
|
@ -471,14 +471,14 @@ def inst_graph(request, compute_id, vname):
|
||||||
datasets['cpu'].pop(0)
|
datasets['cpu'].pop(0)
|
||||||
|
|
||||||
for blk in blk_usage:
|
for blk in blk_usage:
|
||||||
if cookies.get('hdd') == '{}' or not cookies.get('hdd') or not blk_usage:
|
if cookies.get('blk') == '{}' or not cookies.get('blk') or not blk_usage:
|
||||||
datasets_wr.append(0)
|
datasets_wr.append(0)
|
||||||
datasets_rd.append(0)
|
datasets_rd.append(0)
|
||||||
else:
|
else:
|
||||||
datasets['hdd'] = eval(cookies.get('hdd'))
|
datasets['blk'] = eval(cookies.get('blk'))
|
||||||
try:
|
try:
|
||||||
datasets_rd = datasets['hdd'][blk['dev']][0]
|
datasets_rd = datasets['blk'][blk['dev']][0]
|
||||||
datasets_wr = datasets['hdd'][blk['dev']][1]
|
datasets_wr = datasets['blk'][blk['dev']][1]
|
||||||
except:
|
except:
|
||||||
blk_error = True
|
blk_error = True
|
||||||
|
|
||||||
|
@ -518,14 +518,14 @@ def inst_graph(request, compute_id, vname):
|
||||||
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]
|
cookie_net[net['dev']] = [datasets_rx, datasets_tx]
|
||||||
|
|
||||||
data = json.dumps({'status': status, 'cpudata': datasets['cpu'], 'hdddata': json_blk, 'netdata': json_net, 'timeline': datasets['timer']})
|
data = json.dumps({'status': status, 'cpudata': datasets['cpu'], 'blkdata': json_blk, 'netdata': json_net, 'timeline': datasets['timer']})
|
||||||
|
|
||||||
response = HttpResponse()
|
response = HttpResponse()
|
||||||
response['Content-Type'] = "text/javascript"
|
response['Content-Type'] = "text/javascript"
|
||||||
if status == 1:
|
if status == 1:
|
||||||
response.cookies['cpu'] = datasets['cpu']
|
response.cookies['cpu'] = datasets['cpu']
|
||||||
response.cookies['timer'] = datasets['timer']
|
response.cookies['timer'] = datasets['timer']
|
||||||
response.cookies['hdd'] = cookie_blk
|
response.cookies['blk'] = cookie_blk
|
||||||
response.cookies['net'] = cookie_net
|
response.cookies['net'] = cookie_net
|
||||||
response.write(data)
|
response.write(data)
|
||||||
return response
|
return response
|
|
@ -870,10 +870,7 @@
|
||||||
</script>
|
</script>
|
||||||
<script src="{{ STATIC_URL }}js/Chart.min.js"></script>
|
<script src="{{ STATIC_URL }}js/Chart.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
$( "#graphics" ).click();
|
$('#chartgraphs').on('shown.bs.tab', function (event) {
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
$('#chartgraphs').on('shown.bs.tab', function (e) {
|
|
||||||
var cpuLineData = {
|
var cpuLineData = {
|
||||||
labels : [0, 0, 0, 0, 0],
|
labels : [0, 0, 0, 0, 0],
|
||||||
datasets : [
|
datasets : [
|
||||||
|
@ -969,25 +966,37 @@ $( "#graphics" ).click();
|
||||||
netChart['{{ forloop.counter0 }}'] = new Chart(net_ctx_{{ forloop.counter0 }}).Line(netLineData, netOpt);
|
netChart['{{ forloop.counter0 }}'] = new Chart(net_ctx_{{ forloop.counter0 }}).Line(netLineData, netOpt);
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
function graph_usage() {
|
window.setInterval(function graph_usage() {
|
||||||
$.getJSON('{% url 'inst_graph' compute_id vname %}', function (data) {
|
$.getJSON('{% url 'inst_graph' compute_id vname %}', function (data) {
|
||||||
cpuChart.scale.xLabels = data.timeline;
|
cpuChart.scale.xLabels = data.timeline;
|
||||||
for (var i = 0; i < 5; i++) {
|
for (var i = 0; i < data.cpudata.length; i++) {
|
||||||
cpuChart.datasets[0].points[i].value = data.cpudata[i];
|
cpuChart.datasets[0].points[i].value = data.cpudata[i];
|
||||||
}
|
}
|
||||||
cpuChart.update();
|
cpuChart.update();
|
||||||
|
|
||||||
|
for (var j = 0; j < data.blkdata.length; j++) {
|
||||||
|
diskChart[data.blkdata[j].dev].scale.xLabels = data.timeline;
|
||||||
|
|
||||||
|
for (var i = 0; i < data.blkdata[j].data[0].length; i++) {
|
||||||
|
diskChart[data.blkdata[j].dev].datasets[0].points[i].value = data.blkdata[j].data[0][i];
|
||||||
|
diskChart[data.blkdata[j].dev].datasets[1].points[i].value = data.blkdata[j].data[1][i];
|
||||||
|
}
|
||||||
|
|
||||||
|
diskChart[data.blkdata[j].dev].update();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var j = 0; j < data.netdata.length; j++) {
|
||||||
|
netChart[data.netdata[j].dev].scale.xLabels = data.timeline;
|
||||||
|
|
||||||
|
for (var i = 0; i < data.netdata[j].data[0].length; i++) {
|
||||||
|
netChart[data.netdata[j].dev].datasets[0].points[i].value = data.netdata[j].data[0][i];
|
||||||
|
netChart[data.netdata[j].dev].datasets[1].points[i].value = data.netdata[j].data[1][i];
|
||||||
|
}
|
||||||
|
|
||||||
|
netChart[data.netdata[j].dev].update();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}, 6000);
|
||||||
|
|
||||||
{##}
|
|
||||||
{# $(function(f) {#}
|
|
||||||
{# window.setInterval('graph_usage()', 2000);#}
|
|
||||||
{# });#}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
Loading…
Reference in a new issue