From 6660c595ba64bd886ff912a544f02c31a8282891 Mon Sep 17 00:00:00 2001 From: Florian N Date: Thu, 20 Feb 2014 21:00:14 -0500 Subject: [PATCH] add all data to urls --- main/views.py | 6 +---- pydash/urls.py | 2 ++ static/js/dashboard.js | 15 +++++++++++ templates/main.html | 13 ++++++--- usage/views.py | 61 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 88 insertions(+), 9 deletions(-) diff --git a/main/views.py b/main/views.py index f6ec73d..1cc9c5e 100755 --- a/main/views.py +++ b/main/views.py @@ -317,11 +317,7 @@ def get_netstat(): @login_required(login_url='/login/') def getall(request): - return render_to_response('main.html', {'gethostname': get_platform()['hostname'], - 'getplatform': get_platform()['osname'], - 'getkernel': get_platform()['kernel'], - 'getcpus': get_cpus(), - 'time_refresh': time_refresh, + return render_to_response('main.html', {'time_refresh': time_refresh, 'time_refresh_long': time_refresh_long, 'time_refresh_net': time_refresh_net, 'version': version diff --git a/pydash/urls.py b/pydash/urls.py index 60eff05..9841377 100644 --- a/pydash/urls.py +++ b/pydash/urls.py @@ -24,6 +24,8 @@ urlpatterns = patterns('', url(r'^info/proc/$', 'usage.views.getproc', name='getproc'), url(r'^info/getdiskio/$', 'usage.views.getdiskio', name='getdiskio'), url(r'^info/loadaverage/$', 'usage.views.loadaverage', name='loadaverage'), + url(r'^info/platform/([\w\-\.]+)/$', 'usage.views.platform', name='platform'), + url(r'^info/getcpus/([\w\-\.]+)/$', 'usage.views.getcpus', name='getcpus'), url(r'^info/getnetstat/$', 'usage.views.getnetstat', name='getnetstat') ) diff --git a/static/js/dashboard.js b/static/js/dashboard.js index 2411923..5b41e06 100644 --- a/static/js/dashboard.js +++ b/static/js/dashboard.js @@ -103,6 +103,21 @@ var dashboard = {}; dashboard.getUptime = function() { get_os_data('/info/uptime/', "#get-uptime"); } +dashboard.getOSname = function() { + get_os_data('/info/platform/osname/', "#get-osname"); + } +dashboard.getHostname = function() { + get_os_data('/info/platform/hostname/', "#get-hostname"); + } +dashboard.getKernel = function() { + get_os_data('/info/platform/kernel/', "#get-kernel"); + } +dashboard.getCPUcount = function() { + get_os_data('/info/getcpus/count/', "#get-cpucount"); + } +dashboard.getCPUtype = function() { + get_os_data('/info/getcpus/type/', "#get-cputype"); + } dashboard.getDisk = function() { $.getJSON('/info/getdisk/', function(data) { destroy_dataTable("get_disk"); diff --git a/templates/main.html b/templates/main.html index 521ebc9..1362f5d 100644 --- a/templates/main.html +++ b/templates/main.html @@ -72,11 +72,11 @@

- OS: {{ getplatform }}
+ OS:
Uptime: Hours
- Hostname: {{ gethostname }}
- Kernel: {{ getkernel }}
- CPU(s): {{ getcpus.cpus }} x {{ getcpus.type }} + Hostname:
+ Kernel:
+ CPU(s): x

@@ -407,7 +407,12 @@ $(function pageLoad() { cpuu_usage(); traffic_usage(); disk_io(); + dashboard.getOSname(); dashboard.getUptime(); + dashboard.getHostname(); + dashboard.getKernel(); + dashboard.getCPUcount(); + dashboard.getCPUtype(); dashboard.getDisk(); dashboard.getUsers(); dashboard.getNetstat(); diff --git a/usage/views.py b/usage/views.py index dc53442..33cdffc 100755 --- a/usage/views.py +++ b/usage/views.py @@ -49,6 +49,67 @@ def getnetstat(request): response['Content-Type'] = "text/javascript" response.write(data) return response + +@login_required(login_url='/login/') +def platform(request, name): + """ + Return the hostname + """ + getplatform = get_platform() + hostname = getplatform['hostname'] + osname = getplatform['osname'] + kernel = getplatform['kernel'] + + if name == 'hostname': + try: + data = hostname + except Exception: + data = None + + if name == 'osname': + try: + data = osname + except Exception: + data = None + + if name == 'kernel': + try: + data = kernel + except Exception: + data = None + + data = json.dumps(data) + response = HttpResponse() + response['Content-Type'] = "text/javascript" + response.write(data) + return response + +@login_required(login_url='/login/') +def getcpus(request, name): + """ + Return the CPU number and type/model + """ + getcpus = get_cpus() + cputype = getcpus['type'] + cpucount = getcpus['cpus'] + + if name == 'type': + try: + data = cputype + except Exception: + data = None + + if name == 'count': + try: + data = cpucount + except Exception: + data = None + + data = json.dumps(data) + response = HttpResponse() + response['Content-Type'] = "text/javascript" + response.write(data) + return response @login_required(login_url='/login/')