Skip to content

Commit 88eb220

Browse files
Split cloudstats resource usage graphs to another page (#100)
* Split cloudstats resource usage graphs to another page * Docs images for cloudstats resource usage graphs
1 parent c1b4819 commit 88eb220

File tree

8 files changed

+65
-34
lines changed

8 files changed

+65
-34
lines changed

cloudstats/templates/cloudstats/index.html

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ <h3>{% translate "Your projects" %}</h3>
1919
{% endif %}
2020

2121
{% if request.user.is_staff %}
22-
{% include "nav_last_month.html" %}
2322

2423
<h3>{% translate "All projects" %}</h3>
25-
<h4>{% translate "CPU used" %}</h4>
26-
<div id="graph_cpu"></div>
27-
<h4>{% translate "Memory used" %}</h4>
28-
<div id="graph_mem"></div>
24+
<div class="mb-4">
25+
<a href="{% url 'resource_graphs' %}" class="btn btn-primary">
26+
{% translate "Resource Usage Graphs" %}
27+
</a>
28+
</div>
2929
<h4>{% translate "Projects" %}</h4>
3030
Total physical cores: {{physical_cores | floatformat:0}}<br>
3131
Total physical memory: {{physical_memory | floatformat:0}} GB<br>
@@ -58,30 +58,4 @@ <h4>{% translate "Projects" %}</h4>
5858
</table>
5959
{% endif %}
6060

61-
{% if request.user.is_staff %}
62-
<script>
63-
function loadGraphs(delta){
64-
loadGraph('graph_cpu', 'graph/cpu.json?delta=' + delta);
65-
loadGraph('graph_mem', 'graph/mem.json?delta=' + delta);
66-
}
67-
$(document).ready(function(){
68-
loadGraphs(60*60*24*7);
69-
70-
$('#myTabs a').click(function (e) {
71-
if($(this).attr('href') == '#last_month'){
72-
loadGraphs(60*60*24*30);
73-
}
74-
if($(this).attr('href') == '#last_week'){
75-
loadGraphs(60*60*24*7);
76-
}
77-
if($(this).attr('href') == '#last_day'){
78-
loadGraphs(60*60*24);
79-
}
80-
if($(this).attr('href') == '#last_hour'){
81-
loadGraphs(60*60);
82-
}
83-
})
84-
});
85-
</script>
86-
{% endif %}
8761
{% endblock content %}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{% extends 'base.html' %}
2+
{% load humanize %}
3+
{% load i18n %}
4+
5+
{% block title %}{% translate "Your cloud use - Resource Usage Graphs" %}{% endblock title %}
6+
7+
{% block content %}
8+
<h1>{% translate "Your cloud use" %}</h1>
9+
<h2>{% translate "Resource Usage Graphs" %}</h2>
10+
11+
{% if request.user.is_staff %}
12+
{% include "nav_last_month.html" %}
13+
14+
<h3>{% translate "All projects" %}</h3>
15+
<h4>{% translate "CPU used" %}</h4>
16+
<div id="graph_cpu"></div>
17+
<h4>{% translate "Memory used" %}</h4>
18+
<div id="graph_mem"></div>
19+
20+
<script>
21+
function loadGraphs(delta){
22+
loadGraph('graph_cpu', 'graph/cpu.json?delta=' + delta);
23+
loadGraph('graph_mem', 'graph/mem.json?delta=' + delta);
24+
}
25+
$(document).ready(function(){
26+
loadGraphs(60*60*24*7);
27+
28+
$('#myTabs a').click(function (e) {
29+
if($(this).attr('href') == '#last_month'){
30+
loadGraphs(60*60*24*30);
31+
}
32+
if($(this).attr('href') == '#last_week'){
33+
loadGraphs(60*60*24*7);
34+
}
35+
if($(this).attr('href') == '#last_day'){
36+
loadGraphs(60*60*24);
37+
}
38+
if($(this).attr('href') == '#last_hour'){
39+
loadGraphs(60*60);
40+
}
41+
})
42+
});
43+
</script>
44+
{% endif %}
45+
{% endblock content %}

cloudstats/tests.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ def test_cloudstats_admin(self):
2121
self.assertContains(response, 'Your projects')
2222
self.assertContains(response, 'All projects')
2323

24+
def test_cloudstats_resource_graphs(self):
25+
response = self.admin_client.get('/secure/cloudstats/resource_graphs/')
26+
self.assertEqual(response.status_code, 200)
27+
self.assertContains(response, 'All projects')
28+
2429
def test_cloudstats_graph(self):
2530
for i in ['cpu', 'mem']:
26-
response = self.admin_client.get('/secure/cloudstats/graph/{i}.json?delta=3600'.format(
31+
response = self.admin_client.get('/secure/cloudstats/resource_graphs/graph/{i}.json?delta=3600'.format(
2732
i=i))
2833
self.assertEqual(response.status_code, 200)
2934
self.assertJSONKeys(response, ['data', 'layout'])

cloudstats/urls.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
urlpatterns = [
55
path('', views.index),
6-
path('graph/cpu.json', views.projects_graph_cpu),
7-
path('graph/mem.json', views.projects_graph_mem),
6+
path('resource_graphs/', views.resource_graphs, name='resource_graphs'),
7+
path('resource_graphs/graph/cpu.json', views.projects_graph_cpu),
8+
path('resource_graphs/graph/mem.json', views.projects_graph_mem),
89
path('<str:project>/', views.project),
910
path('<str:project>/graph/cpu.json', views.project_graph_cpu),
1011
path('<str:project>/graph/memory.json', views.project_graph_memory),

cloudstats/views.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ def index(request):
130130
return render(request, 'cloudstats/index.html', context)
131131

132132

133+
@login_required
134+
def resource_graphs(request):
135+
return render(request, 'cloudstats/resource_graphs.html')
136+
137+
133138
@login_required
134139
@openstackproject_or_staff
135140
def project(request, project):

docs/cloudstats.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ The stats of the VM running on Openstack can be viewed. This is using the stats
44
## Screenshots
55
### Overall use
66
![Overall use](cloudstats.png)
7+
![Overall use - Resource Usage Graphs](cloudstats_resource_graphs.png)
78
### Use within a project
89
![Use within a project](cloudstats_project.png)
910
### Use within a VM

docs/cloudstats.png

-119 KB
Loading
103 KB
Loading

0 commit comments

Comments
 (0)