Commit c85691f6 by Kálmán Viktor

dashboard: add graph time options for node graphs

parent 83635528
......@@ -29,12 +29,20 @@
</div><!-- id:node-details-traits -->
</div>
<div class="col-md-8">
<div class="text-center">
{% for o in graph_time_options %}
<a class="btn btn-default btn-xs"
href="?graph_time={{ o.time }}">
{{ o.name }}
</a>
{% endfor %}
</div>
{% if graphite_enabled %}
<img src="{% url "dashboard.views.node-graph" node.pk "cpu" "6h" %}" style="width:100%"/>
<img src="{% url "dashboard.views.node-graph" node.pk "memory" "6h" %}" style="width:100%"/>
<img src="{% url "dashboard.views.node-graph" node.pk "network" "6h" %}" style="width:100%"/>
<img src="{% url "dashboard.views.node-graph" node.pk "vm" "6h" %}" style="width:100%"/>
<img src="{% url "dashboard.views.node-graph" node.pk "alloc" "6h" %}" style="width:100%"/>
<img src="{% url "dashboard.views.node-graph" node.pk "cpu" graph_time %}" style="width:100%"/>
<img src="{% url "dashboard.views.node-graph" node.pk "memory" graph_time %}" style="width:100%"/>
<img src="{% url "dashboard.views.node-graph" node.pk "network" graph_time %}" style="width:100%"/>
<img src="{% url "dashboard.views.node-graph" node.pk "vm" graph_time %}" style="width:100%"/>
<img src="{% url "dashboard.views.node-graph" node.pk "alloc" graph_time %}" style="width:100%"/>
{% endif %}
</div>
</div>
......
......@@ -25,11 +25,19 @@
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<div class="pull-right">
{% for o in graph_time_options %}
<a class="btn btn-default btn-xs"
href="?graph_time={{ o.time }}">
{{ o.name }}
</a>
{% endfor %}
</div>
<h3 class="no-margin"><i class="fa fa-area-chart"></i> {% trans "Graphs" %}</h3>
</div>
<div class="text-center">
<img src="{% url "dashboard.views.node-list-graph" "alloc" "6h" %}"/>
<img src="{% url "dashboard.views.node-list-graph" "vm" "6h" %}"/>
<img src="{% url "dashboard.views.node-list-graph" "alloc" graph_time %}"/>
<img src="{% url "dashboard.views.node-list-graph" "vm" graph_time %}"/>
</div>
</div>
</div><!-- -col-md-12 -->
......
......@@ -37,9 +37,11 @@ from vm.models import Node, NodeActivity, Trait
from ..forms import TraitForm, HostForm, NodeForm
from ..tables import NodeListTable
from .util import GraphMixin
class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin,
GraphMixin, DetailView):
template_name = "dashboard/node-detail.html"
model = Node
form = None
......@@ -106,7 +108,8 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
return redirect(self.object.get_absolute_url())
class NodeList(LoginRequiredMixin, SuperuserRequiredMixin, SingleTableView):
class NodeList(LoginRequiredMixin, SuperuserRequiredMixin,
GraphMixin, SingleTableView):
template_name = "dashboard/node-list.html"
table_class = NodeListTable
table_pagination = False
......
......@@ -535,5 +535,28 @@ class AclUpdateView(LoginRequiredMixin, View, SingleObjectMixin):
return redirect("%s#access" % self.instance.get_absolute_url())
class GraphMixin(object):
graph_time_options = [
{'time': "1h", 'name': _("1 hour")},
{'time': "1d", 'name': _("1 day")},
{'time': "1w", 'name': _("1 week")},
{'time': "4w", 'name': _("1 month")},
]
default_graph_time = "6h"
def get_context_data(self, *args, **kwargs):
context = super(GraphMixin, self).get_context_data(*args, **kwargs)
graph_time = self.request.GET.get("graph_time",
self.default_graph_time)
if not re.match("^[0-9]{1,2}[hdwy]$", graph_time):
messages.warning(self.request, _("Bad graph time format, "
"available periods are: "
"h, d, w, and y."))
graph_time = self.default_graph_time
context['graph_time'] = graph_time
context['graph_time_options'] = self.graph_time_options
return context
def absolute_url(url):
return urljoin(settings.DJANGO_URL, url)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment