mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-23 22:55:23 +00:00
instance view: added logs section to graphs (renamed graphs -> stats)
This commit is contained in:
parent
fdca3cef9c
commit
839b8d420d
3 changed files with 69 additions and 6 deletions
|
@ -84,8 +84,8 @@
|
|||
</li>
|
||||
<li role="presentation">
|
||||
<a href="#graphics" id="chartgraphs" class="action-button" aria-controls="graphics" role="tab" data-toggle="tab">
|
||||
<span id="action-block" class="glyphicon glyphicon-signal" aria-hidden="true"></span>
|
||||
{% trans "Graphs" %}
|
||||
<span id="action-block" class="glyphicon glyphicon-stats" aria-hidden="true"></span>
|
||||
{% trans "Stats" %}
|
||||
</a>
|
||||
</li>
|
||||
<li role="presentation">
|
||||
|
@ -1043,6 +1043,11 @@
|
|||
{% trans "Real Time" %}
|
||||
</a>
|
||||
</li>
|
||||
<li role="presentation">
|
||||
<a href="#logs" aria-controls="logs" role="tab" data-toggle="tab" onclick='update_logs_table("{{ vname }}");'>
|
||||
{% trans "Logs" %}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<!-- Tab panes -->
|
||||
<div class="tab-content">
|
||||
|
@ -1089,6 +1094,23 @@
|
|||
{% endfor %}
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="logs">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped sortable-theme-bootstrap" id="logs_table" data-sortable>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{% trans "Date" %}</th>
|
||||
<th>{% trans "User" %}</th>
|
||||
<th>{% trans "Message" %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="searchable">
|
||||
<tr><td colspan="3"><i>None ...</i></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1467,4 +1489,19 @@
|
|||
});
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
function update_logs_table(vname) {
|
||||
$.getJSON('/logs/vm_logs/'+vname+'/', function(data) {
|
||||
var logs = "";
|
||||
$.each(data, function(id) {
|
||||
row = data[id];
|
||||
console.log(row);
|
||||
logs += '<tr><td style="width:150px">'+row['date']+'</td>';
|
||||
logs += '<td>'+row['user']+'</td>';
|
||||
logs += '<td>'+row['message']+'</td></tr>';
|
||||
});
|
||||
$("#logs_table > tbody").html(logs);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
|
@ -4,4 +4,5 @@ from . import views
|
|||
urlpatterns = [
|
||||
url(r'^$', views.showlogs, name='showlogs'),
|
||||
url(r'^(?P<page>[0-9]+)/$', views.showlogs, name='showlogspage'),
|
||||
url(r'^vm_logs/(?P<vname>[\w\-\.]+)/$', views.vm_logs, name='vm_logs'),
|
||||
]
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
from django.shortcuts import render
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from instances.models import Instance
|
||||
from logs.models import Logs
|
||||
from django.conf import settings
|
||||
import json
|
||||
|
||||
|
||||
def addlogmsg(user, instance, message):
|
||||
|
@ -14,15 +17,13 @@ def addlogmsg(user, instance, message):
|
|||
add_log_msg.save()
|
||||
|
||||
|
||||
@login_required
|
||||
def showlogs(request, page=1):
|
||||
"""
|
||||
:param request:
|
||||
:return:
|
||||
"""
|
||||
|
||||
if not request.user.is_authenticated():
|
||||
return HttpResponseRedirect(reverse('index'))
|
||||
|
||||
if not request.user.is_superuser:
|
||||
return HttpResponseRedirect(reverse('index'))
|
||||
|
||||
|
@ -34,3 +35,27 @@ def showlogs(request, page=1):
|
|||
# TODO: remove last element from queryset, but do not affect database
|
||||
|
||||
return render(request, 'showlogs.html', locals())
|
||||
|
||||
@login_required
|
||||
def vm_logs(request, vname):
|
||||
"""
|
||||
:param request:
|
||||
:param vm:
|
||||
:return:
|
||||
"""
|
||||
|
||||
if not request.user.is_superuser:
|
||||
return HttpResponseRedirect(reverse('index'))
|
||||
|
||||
vm = Instance.objects.get(name=vname)
|
||||
logs_ = Logs.objects.filter(instance=vm.name, date__gte=vm.created).order_by('-date')
|
||||
logs = []
|
||||
for l in logs_:
|
||||
log = {}
|
||||
log['user'] = l.user
|
||||
log['instance'] = l.instance
|
||||
log['message'] = l.message
|
||||
log['date'] = l.date.strftime('%x %X')
|
||||
logs.append(log)
|
||||
|
||||
return HttpResponse(json.dumps(logs))
|
||||
|
|
Loading…
Reference in a new issue