diff --git a/README.md b/README.md index e0e0121..90dc94f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ -pyDash - v1.4.2 +pyDash - v1.4.4 [![Follow @hostechs](https://dev.twitter.com/sites/default/files/images_documentation/bird_blue_32.png)](https://twitter.com/hostechs) [![View Profile](https://dlc1-s.licdn.com/sites/default/files/InBug-30px-R.png)](http://www.linkedin.com/in/hostechs/) ====== + +[![Flattr this](http://api.flattr.com/button/flattr-badge-large.png)](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. @@ -67,8 +71,3 @@ Credits [Dashboard Template](http://www.egrappler.com/templatevamp-free-twitter-bootstrap-admin-template/), [Bootstrap](http://getbootstrap.com/), [Font Awesome](http://fontawesome.io/) - - -Follow [@hostechs](https://twitter.com/hostechs) on Twitter - -[![Flattr this](http://api.flattr.com/button/flattr-badge-large.png)](http://flattr.com/thing/2630601/k3onipydash-on-GitHub "Flattr this") diff --git a/main/views.py b/main/views.py index cee502a..f30e552 100755 --- a/main/views.py +++ b/main/views.py @@ -70,31 +70,31 @@ def get_ipaddress(): """ Get the IP Address """ + data = [] try: - if get_platform()['osname'] == "Linux": - pipe = os.popen("ip addr | grep -A3 'LOWER_UP' | awk '{if ($2 == \"forever\"){printf \"unavailable,\"} else{ printf \"%s,\",$2}}'|awk -F,, '{print $0}'") - else: - pipe = os.popen("ip addr | grep -A3 'LOWER_UP' | awk '{if ($2 == \"forever\"){printf \"unavailable,,\"} else{ 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 = [i.split(',', 4) for i in data] - if len(data) == 2: - del data[0] - if len(data) > 2: - data = data[1:-1] - - 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(): @@ -248,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 diff --git a/pydash/settings.py b/pydash/settings.py index ade20e6..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.2" +VERSION = "1.4.4" ALLOWED_HOSTS = ['*'] 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/js/dashboard.js b/static/js/dashboard.js index a2eb107..ad0d12c 100644 --- a/static/js/dashboard.js +++ b/static/js/dashboard.js @@ -234,8 +234,8 @@ 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, diff --git a/templates/main.html b/templates/main.html index 0d1859d..94c37ff 100644 --- a/templates/main.html +++ b/templates/main.html @@ -2,7 +2,7 @@ - + {% block title %}PyDash v{{ version }}{% endblock %} @@ -114,7 +114,11 @@

- + +
+ {% trans "Free" %} + {% trans "Used" %} +
diff --git a/usage/views.py b/usage/views.py index 7d896ba..3a58ac4 100755 --- a/usage/views.py +++ b/usage/views.py @@ -229,7 +229,9 @@ def memusage(request): """ Return Memory Usage in % and numeric """ - datasets = [] + datasets_free = [] + datasets_used = [] + cookie_memory = {} try: mem_usage = get_mem() @@ -242,26 +244,40 @@ def memusage(request): cookies = None if not cookies: - datasets.append(0) + datasets_free.append(0) + datasets_used.append(0) else: datasets = json.loads(cookies) - if len(datasets) > 10: - while datasets: - del datasets[0] - if len(datasets) == 10: + datasets_free = datasets[0] + datasets_used = datasets[1] + + if len(datasets_free) > 10: + while datasets_free: + del datasets_free[0] + if len(datasets_free) == 10: break - if len(datasets) <= 9: - datasets.append(int(mem_usage['usage'])) - if len(datasets) == 10: - datasets.append(int(mem_usage['usage'])) - del datasets[0] + if len(datasets_used) > 10: + while datasets_used: + del datasets_used[0] + if len(datasets_used) == 10: + break + if len(datasets_free) <= 9: + datasets_free.append(int(mem_usage['free'])) + if len(datasets_free) == 10: + datasets_free.append(int(mem_usage['free'])) + del datasets_free[0] + if len(datasets_used) <= 9: + datasets_used.append(int(mem_usage['usage'])) + if len(datasets_used) == 10: + datasets_used.append(int(mem_usage['usage'])) + del datasets_used[0] # Some fix division by 0 Chart.js - if len(datasets) == 10: - if sum(datasets) == 0: - datasets[9] += 0.1 - if sum(datasets) / 10 == datasets[0]: - datasets[9] += 0.1 + if len(datasets_free) == 10: + if sum(datasets_free) == 0: + datasets_free[9] += 0.1 + if sum(datasets_free) / 10 == datasets_free[0]: + datasets_free[9] += 0.1 memory = { 'labels': [""] * 10, @@ -271,15 +287,23 @@ def memusage(request): "strokeColor": "rgba(249,134,33,1)", "pointColor": "rgba(249,134,33,1)", "pointStrokeColor": "#fff", - "data": datasets + "data": datasets_used + }, + { + "fillColor": "rgba(43,214,66,0.5)", + "strokeColor": "rgba(43,214,66,1)", + "pointColor": "rgba(43,214,66,1)", + "pointStrokeColor": "#fff", + "data": datasets_free } ] } + cookie_memory = [datasets_free, datasets_used] data = json.dumps(memory) response = HttpResponse() response['Content-Type'] = "text/javascript" - response.cookies['memory_usage'] = datasets + response.cookies['memory_usage'] = cookie_memory response.write(data) return response