From 3f0910498032217f5c742a04e31288a0134eddbe Mon Sep 17 00:00:00 2001 From: catborise Date: Tue, 19 May 2020 00:38:20 +0300 Subject: [PATCH] add host status checking for statistic request --- computes/templates/overview.html | 43 ++++++++++++++++---------------- computes/views.py | 3 ++- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/computes/templates/overview.html b/computes/templates/overview.html index 7b1965e..5f2e669 100644 --- a/computes/templates/overview.html +++ b/computes/templates/overview.html @@ -226,29 +226,30 @@ } } }); + if (Boolean({{ status }}) === true) { + window.setInterval(function graph_usage() { + $.getJSON('{% url 'compute_graph' compute_id %}', function (data) { + cpuChart.data.labels.push(data.timeline); + memChart.data.labels.push(data.timeline); - window.setInterval(function graph_usage() { - $.getJSON('{% url 'compute_graph' compute_id %}', function (data) { - cpuChart.data.labels.push(data.timeline); - memChart.data.labels.push(data.timeline); + cpuChart.data.datasets[0].data.push(data.cpudata); + if (cpuChart.data.datasets[0].data.length > 10){ + cpuChart.data.labels.shift(); + cpuChart.data.datasets[0].data.shift(); + } + memChart.options.scales.yAxes[0].ticks.max = parseInt(data.memdata.total / 1048576); + memChart.options.scales.yAxes[0].ticks.stepSize = parseInt(data.memdata.total / (1048576 * 5)); + memChart.data.datasets[0].data.push(parseInt(data.memdata.usage / 1048576)); - cpuChart.data.datasets[0].data.push(data.cpudata); - if (cpuChart.data.datasets[0].data.length > 10){ - cpuChart.data.labels.shift(); - cpuChart.data.datasets[0].data.shift(); - } - memChart.options.scales.yAxes[0].ticks.max = parseInt(data.memdata.total / 1048576); - memChart.options.scales.yAxes[0].ticks.stepSize = parseInt(data.memdata.total / (1048576 * 5)); - memChart.data.datasets[0].data.push(parseInt(data.memdata.usage / 1048576)); + if (memChart.data.datasets[0].data.length > 10){ + memChart.data.labels.shift(); + memChart.data.datasets[0].data.shift(); + } - if (memChart.data.datasets[0].data.length > 10){ - memChart.data.labels.shift(); - memChart.data.datasets[0].data.shift(); - } - - cpuChart.update(); - memChart.update(); - }); - }, 5000); + cpuChart.update(); + memChart.update(); + }); + }, 5000); + } {% endblock %} diff --git a/computes/views.py b/computes/views.py index 9f540b0..200baf5 100644 --- a/computes/views.py +++ b/computes/views.py @@ -148,7 +148,8 @@ def overview(request, compute_id): error_messages = [] compute = get_object_or_404(Compute, pk=compute_id) - + status = 'true' if connection_manager.host_is_up(compute.type, compute.hostname) else 'false' + try: conn = wvmHostDetails(compute.hostname, compute.login,