diff --git a/README.md b/README.md index 725194b..90dc94f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,11 @@ -pyDash - v1.4 +pyDash - v1.4.4 [](https://twitter.com/hostechs) [](http://www.linkedin.com/in/hostechs/) ====== -A small web monitoring dashboard for your linux pc/server writen in Python and Django + Chart.js. + +[](http://flattr.com/thing/2630601/k3onipydash-on-GitHub "Flattr this") + + +A small web-based monitoring dashboard for your linux pc/server writen in Python and Django + Chart.js. The dashboard is built using only Python libraries available in the main Python distribution, trying to create a small list of dependencies without the need of installing many packages or libraries. diff --git a/main/views.py b/main/views.py index f6ec73d..f30e552 100755 --- a/main/views.py +++ b/main/views.py @@ -70,25 +70,31 @@ def get_ipaddress(): """ Get the IP Address """ + data = [] try: - pipe = os.popen(" ip addr | grep -A3 'LOWER_UP' | awk '{printf \"%s,\",$2}'|awk -F,, '{print $0}'") - data = pipe.read().strip().split(',,') - pipe.close() + eth = os.popen("ip addr | grep LOWER_UP | awk '{print $2}'") + iface = eth.read().strip().replace(':','').split('\n') + eth.close() + del iface[0] + + for i in iface: + pipe = os.popen("ip addr show " + i + "| awk '{if ($2 == \"forever\"){!$2} else {print $2}}'") + data1 = pipe.read().strip().split('\n') + pipe.close() + if len(data1) == 2: + data1.append('unavailable', 'unavailable') + if len(data1) == 3: + data1.append('unavailable') + data1[0] = i + data.append(data1) + + ips = {'interface': iface, 'itfip': data} + + data = ips + + except Exception,err: + data = str(err) - data = [n for n in data if not n.startswith(('lo', '127'))] - data = [i.split(',', 4) for i in data] - - itf = [] - for e in data: - itf.append(e[0].strip(':')) - - ips = {'interface': itf, 'itfip': data} - - data = ips - - except Exception,err: - data = str(err) - return data def get_cpus(): @@ -123,14 +129,14 @@ def get_users(): data = pipe.read().strip().split('\n') pipe.close() - data = [i.split(None, 3) for i in data] - + if data == [""]: + data = None + else: + data = [i.split(None, 3) for i in data] + except Exception, err: data = str(err) - if data[0] == []: - data = [['No', 'data', 'available']] - return data def get_traffic(request): @@ -242,7 +248,7 @@ def get_mem(): percent = (100 - ((freemem * 100) / allmem)) usage = (allmem - freemem) - mem_usage = {'usage': usage, 'percent': percent} + mem_usage = {'usage': usage, 'free': freemem, 'percent': percent} data = mem_usage @@ -308,20 +314,13 @@ def get_netstat(): except Exception, err: data = str(err) - if data[0] == []: - data = [['No', 'data', 'available']] - return data @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/settings.py b/pydash/settings.py index afab89c..b8942ff 100644 --- a/pydash/settings.py +++ b/pydash/settings.py @@ -19,7 +19,6 @@ BASE_DIR = os.path.dirname(os.path.dirname(__file__)) # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = '1)$crmowu-23tz@i2-d=7tb3t+1u&(pm!lnjyuarki^72h!3af' - # SECURITY WARNING: don't run with debug turned on in production! DEBUG = False @@ -36,7 +35,7 @@ TIME_JS_REFRESH = 30000 TIME_JS_REFRESH_LONG = 120000 TIME_JS_REFRESH_NET = 2000 -VERSION = 1.4 +VERSION = "1.4.4" ALLOWED_HOSTS = ['*'] 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/css/dashboard.css b/static/css/dashboard.css index 86aad04..5ade332 100644 --- a/static/css/dashboard.css +++ b/static/css/dashboard.css @@ -403,3 +403,19 @@ h6.bigstats { padding: 0 0.3em; border-style: solid; } +.memf { + border-color: rgb(43,214,66); + margin: 0.5em; + border-style: solid; + border-width: 0 0 0 1em; + padding: 0 0.3em; + border-style: solid; +} +.memu { + border-color: rgb(249,134,33); + margin: 0.5em; + border-style: solid; + border-width: 0 0 0 1em; + padding: 0 0.3em; + border-style: solid; +} diff --git a/static/css/style.css b/static/css/style.css index 42c55ff..ce10fee 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -410,12 +410,8 @@ textarea { .widget-content { padding: 20px 15px 15px; - background: #FFF; - - border: 1px solid #D5D5D5; - -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; @@ -423,7 +419,6 @@ textarea { .widget-header+.widget-content { border-top: none; - -webkit-border-top-left-radius: 0; -webkit-border-top-right-radius: 0; -moz-border-radius-topleft: 0; diff --git a/static/js/dashboard.js b/static/js/dashboard.js index 2411923..ad0d12c 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"); @@ -137,11 +152,15 @@ dashboard.getUsers = function() { aoColumns: [ { sTitle: "USER" }, { sTitle: "TTY" }, - { sTitle: "LOOGED IN FROM" } + { sTitle: "LOOGED IN FROM", + sDefaultContent: "unavailable" } ], - bPaginate: false, - bFilter: true, - sDom: "lrtip", + aaSorting: [ + [0, "desc"] + ], + bPaginate: true, + sPaginationType: "two_button", + bFilter: false, bAutoWidth: false, bInfo: false }).fadeIn(); @@ -215,8 +234,9 @@ dashboard.getIps = function() { aoColumns: [ { sTitle: "INTERFACE" }, { sTitle: "MAC ADDRESS" }, - { sTitle: "IPv4 ADDRESS" }, - { sTitle: "IPv6 ADDRESS" } + { sTitle: "IP ADDRESS" }, + { sTitle: "IP ADDRESS", + sDefaultContent: "unavailable" } ], bPaginate: false, bFilter: true, @@ -230,3 +250,12 @@ dashboard.getIps = function() { }); } +//Expand-Contract div/table +$(document).ready(function() { + $(".widget-content").show(); + $(".widget-header").click(function() + { + $(this).next(".widget-content").slideToggle(500); + $("i",this).toggleClass("icon-minus icon-plus"); + }); +}); diff --git a/templates/main.html b/templates/main.html index 521ebc9..94c37ff 100644 --- a/templates/main.html +++ b/templates/main.html @@ -2,7 +2,7 @@
- +