diff --git a/README.md b/README.md index 171bbe8..f5e5af0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -pyDash - v1.2 +pyDash - v1.3 ====== A small web monitoring dashboard for your linux pc/server writen in Python and Django + Chart.js. @@ -9,7 +9,7 @@ The dashboard is built using only Python libraries available in the main Python Current dependencies: - == Django 1.6.1 - - >= Python 2.6 + - == Python 2.x __[View Demo](http://pydash.hostechs.com/)__ diff --git a/main/views.py b/main/views.py index ad1d9ef..ec3b24f 100755 --- a/main/views.py +++ b/main/views.py @@ -71,16 +71,16 @@ def get_ipaddress(): Get the IP Address """ try: - pipe = os.popen(" ip addr | grep -A3 'state UP' | awk '{printf \"%s,\",$2}'|awk -F, '{print $1, $2, $3}'") - data = pipe.read().strip().split('\n') + pipe = os.popen(" ip addr | grep -A3 'LOWER_UP' | awk '{printf \"%s,\",$2}'|awk -F,, '{print $1, $2, $3}'") + data = pipe.read().strip().split(' ') pipe.close() - data = [i.split(None, 3) for i in data] + data = [n for n in data if not n.startswith(('lo', '127'))] + data = [i.split(',', 3) for i in data] + + itf = [] for e in data: - if len(e) > 3: - itf = dict(zip([iter(e[0].strip(':'))])) - else: - itf = [e[0].strip(':')] + itf.append(e[0].strip(':')) ips = {'interface': itf, 'itfip': data} @@ -255,7 +255,7 @@ def get_cpu_usage(): """ Get the CPU usage and running processes """ - try: + try: pipe = os.popen("ps aux --sort -%cpu,-rss") data = pipe.read().strip().split('\n') pipe.close() @@ -282,17 +282,38 @@ def get_cpu_usage(): return data + def get_load(): """ Get load average """ try: - data = os.getloadavg()[0] + data = os.getloadavg()[0] except Exception, err: - data = str(err) + data = str(err) return data + +def get_netstat(): + """ + Get ports and applications + """ + try: + pipe = os.popen("ss -tnp | grep ESTAB | awk '{print $4, $5}'| sed 's/::ffff://g' | awk -F: '{print $1, $2}' | sort -n | uniq -c") + data = pipe.read().strip().split('\n') + pipe.close() + + data = [i.split(None, 4) for i in data] + + except Exception, err: + data = str(err) + if data[0] == []: + data = [['No', 'data', 'available']] + + return data + + @login_required(login_url='/login/') def getall(request): diff --git a/pydash/settings.py b/pydash/settings.py index 4e56a0a..0238db5 100644 --- a/pydash/settings.py +++ b/pydash/settings.py @@ -36,7 +36,7 @@ TIME_JS_REFRESH = 30000 TIME_JS_REFRESH_LONG = 120000 TIME_JS_REFRESH_NET = 2000 -VERSION = 1.2 +VERSION = 1.3 ALLOWED_HOSTS = ['*'] diff --git a/pydash/urls.py b/pydash/urls.py index 4ef5663..60eff05 100644 --- a/pydash/urls.py +++ b/pydash/urls.py @@ -23,7 +23,8 @@ urlpatterns = patterns('', url(r'^info/gettraffic/$', 'usage.views.gettraffic', name='gettraffic'), 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/loadaverage/$', 'usage.views.loadaverage', name='loadaverage'), + url(r'^info/getnetstat/$', 'usage.views.getnetstat', name='getnetstat') ) urlpatterns += patterns('', diff --git a/templates/main.html b/templates/main.html index 29935e9..2d54372 100644 --- a/templates/main.html +++ b/templates/main.html @@ -42,6 +42,7 @@