From efa0bc15bebb1739c2acba586f00c499c9cae145 Mon Sep 17 00:00:00 2001 From: Florian N Date: Sun, 2 Feb 2014 19:11:44 -0500 Subject: [PATCH] code update --- main/views.py | 45 +++++++++++++++++++++++++++++++++++- static/css/bootstrap.min.css | 14 ++++++++++- templates/base_auth.html | 2 +- templates/ip.html | 4 ++-- templates/main.html | 7 +++--- usage/views.py | 3 +++ 6 files changed, 66 insertions(+), 9 deletions(-) diff --git a/main/views.py b/main/views.py index 23861fe..9adf051 100755 --- a/main/views.py +++ b/main/views.py @@ -81,6 +81,48 @@ def get_ipaddress(): data = pipe.read().strip().split() pipe.close() + data = [n for n in data if not n.startswith(('lo', '127'))] + #x=len(data) + + #data1 = list(range(x)) + + #data = dict(zip(data1,data)) + #data = data1 + + #data = chunks(data, 2) + + + itf = dict(zip(*[iter(data)] * 2)) + ips = {'interface': itf, 'itfip': data} + + data = ips + + except Exception,err: + data = str(err) + + return data + +def get_traffic(request): + """ + Get the traffic for the specified interface + """ + try: + pipe = os.popen("cat /proc/net/dev |" + "grep " + request + "| awk {'print $1, $9'}") + data = pipe.read().strip().split(':',1)[-1] + pipe.close() + + #data = [n for n in data if not n.startswith(('lo'))] + data = data.split() + + traffic_in = int(data[0]) + traffic_out = int(data[1]) + + #percent = (100 - ((freemem * 100) / allmem)) + #usage = (allmem - freemem) + + all_traffic = {'traffic_in': traffic_in, 'traffic_out': traffic_out} + + data = all_traffic except Exception,err: data = str(err) @@ -108,7 +150,7 @@ def get_disk(): #data = commands.getoutput("df -Ph | column -t") pipe = os.popen("df -Ph | " + "grep -v Filesystem | " + "awk '{print $1, $2, $3, $4, $5, $6}'") data = pipe.read().strip().split() - pipe.close() + pipe.close() #x=len(data) @@ -170,5 +212,6 @@ def getall(request): 'getplatform': get_platform(), 'getdisk': get_disk(), 'getip': get_ipaddress(), + #'gettraffic': get_traffic(), 'time_refresh': time_refresh }, context_instance=RequestContext(request)) diff --git a/static/css/bootstrap.min.css b/static/css/bootstrap.min.css index 0a7c951..290e388 100644 --- a/static/css/bootstrap.min.css +++ b/static/css/bootstrap.min.css @@ -1862,6 +1862,18 @@ background-repeat:no-repeat; line-height: 22px; padding: 0 6px; } + +.btn-mini-select { + -webkit-border-radius: 3px; + -moz-border-radius: 3px; + -ms-border-radius: 3px; + -o-border-radius: 3px; + border-radius: 3px; + font-size: 11px; + line-height: 18px; + line-height: 18px; + padding: 0 0; +} .btn-primary, .btn-primary:hover, .btn-warning, .btn-warning:hover, .btn-danger, .btn-danger:hover, .btn-success, .btn-success:hover, .btn-info, .btn-info:hover, .btn-inverse, .btn-inverse:hover { text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25); color: #ffffff; @@ -3645,4 +3657,4 @@ filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fbb450', endCo } .invisible { visibility: hidden; -} \ No newline at end of file +} diff --git a/templates/base_auth.html b/templates/base_auth.html index e3f711f..6dedd3f 100644 --- a/templates/base_auth.html +++ b/templates/base_auth.html @@ -4,7 +4,7 @@ - {% block title %}{% endblock %} + {% block title %}PyDash - Authentication{% endblock %} diff --git a/templates/ip.html b/templates/ip.html index 3706bfe..9a7cc37 100644 --- a/templates/ip.html +++ b/templates/ip.html @@ -6,9 +6,9 @@ - {% for data in getip %} + {% for itfip in getip.itfip %} {% cycle '' ''%} - {{data}} + {{itfip}} {% cycle '' '' %} {% endfor %} diff --git a/templates/main.html b/templates/main.html index 4c925c2..544f4f0 100644 --- a/templates/main.html +++ b/templates/main.html @@ -4,7 +4,7 @@ - {% block title %}{% endblock %} + {% block title %}PyDash{% endblock %} @@ -175,7 +175,7 @@ - +
@@ -186,8 +186,7 @@
- 0 - Mbps + {{gettraffic}}
diff --git a/usage/views.py b/usage/views.py index 6f82d4e..79b033b 100755 --- a/usage/views.py +++ b/usage/views.py @@ -6,6 +6,8 @@ from django.utils import simplejson from main.views import * from pydash.settings import TIME_JS_REFRESH +time_refresh = TIME_JS_REFRESH + def cpuusage(request): """ Return CPU Usage in % @@ -188,3 +190,4 @@ def loadaverage(request): response.cookies['load_average'] = datasets response.write(data) return response +