Browse Source

Merge branch 'master' of https://github.com/k3oni/pydash

windows
root 12 years ago
parent
commit
96aad9f10b
  1. 4
      README.md
  2. 41
      main/views.py
  3. 2
      pydash/settings.py
  4. 3
      pydash/urls.py
  5. 93
      templates/main.html
  6. 19
      usage/views.py

4
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/)__

41
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):

2
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 = ['*']

3
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('',

93
templates/main.html

@ -42,6 +42,7 @@
<li><a href="#refresh-ram"><i class="icon-list-alt"></i><span>RAM</span> </a> </li>
<li><a href="#refresh-load"><i class="icon-bolt"></i><span>Load</span> </a> </li>
<li><a href="#refresh-online"><i class="icon-user"></i><span>Users</span> </a> </li>
<li><a href="#refresh-netstat"><i class="icon-angle-down"></i><span>Netstat</span> </a> </li>
<li><a href="#refresh-ispeed"><i class="icon-exchange"></i><span>Network</span> </a> </li>
<li><a href="#refresh-ps"><i class="icon-list-alt"></i><span>Processes</span> </a> </li>
<li></li>
@ -250,32 +251,59 @@
<!-- /row -->
<div class="row">
<div class="span6">
<div class="widget widget-table action-table">
<div class="widget-header"> <i class="icon-group"></i>
<h3>Online</h3>
<div id="refresh-online">
</div>
</div>
<!-- /widget-header -->
<div class="widget-content">
<table class="table table-hover table-condensed table-bordered">
<thead>
<tr>
<th>User</th>
<th>TTY</th>
<th>Logged in from</th>
</tr>
</thead>
<tbody id="get-users">
</tbody>
</table>
</div>
<!-- /widget-content -->
</div>
<!-- /widget -->
</div>
<!-- /span -->
<div class="span6">
<div class="widget widget-table action-table">
<div class="widget-header"> <i class="icon-group"></i>
<h3>Online</h3>
<div id="refresh-online">
</div>
</div>
<!-- /widget-header -->
<div class="widget-content">
<table class="table table-hover table-condensed table-bordered">
<thead>
<tr>
<th>User</th>
<th>TTY</th>
<th>Logged in from</th>
</tr>
</thead>
<tbody id="get-users">
</tbody>
</table>
</div>
<!-- /widget-content -->
</div>
<!-- /widget -->
</div>
<!-- /span -->
<div class="span6">
<div class="widget widget-table action-table">
<div class="widget-header"> <i class="icon-angle-down"></i>
<h3>Netstat</h3>
<div id="refresh-netstat">
</div>
</div>
<!-- /widget-header -->
<div class="widget-content">
<table class="table table-hover table-condensed table-bordered">
<thead>
<tr>
<th>Count</th>
<th>Local IP</th>
<th>Local Port</th>
<th>Foreign</th>
</tr>
</thead>
<tbody id="get-netstat">
</tbody>
</table>
</div>
<!-- /widget-content -->
</div>
<!-- /widget -->
</div>
<!-- /span -->
</div>
<!-- /row -->
@ -357,6 +385,7 @@ function get_os_data(url, element) {
var dashboard = {};
dashboard.getUptime = function() {
get_os_data('/info/uptime/', "#get-uptime");
}
@ -380,6 +409,16 @@ dashboard.getUsers = function() {
$("#get-users").html( tr );
});
}
dashboard.getNetstat = function() {
$.getJSON('/info/getnetstat/', function(data) {
var tr='';
$.each( data, function( index, item){
tr+='<tr><td>'+item[0]+'</td><td>'+item[1]+'</td><td>'+item[2]+'</td><td>'+item[3]+'</td></tr>';
})
tr+='';
$("#get-netstat").html( tr );
});
}
dashboard.getProc = function() {
$.getJSON('/info/proc/', function(data) {
var tr='';
@ -476,6 +515,7 @@ $(function() {
window.setInterval('dashboard.getUptime()', {{ time_refresh_long }});
window.setInterval('dashboard.getDisk()', {{ time_refresh_long }});
window.setInterval('dashboard.getUsers()', {{ time_refresh_long }});
window.setInterval('dashboard.getNetstat()', {{ time_refresh_long }});
});
$(function pageLoad() {
@ -488,6 +528,7 @@ $(function pageLoad() {
dashboard.getUptime();
dashboard.getDisk();
dashboard.getUsers();
dashboard.getNetstat();
dashboard.getIps();
});
</script>

19
usage/views.py

@ -33,6 +33,24 @@ time_refresh = TIME_JS_REFRESH
time_refresh_long = TIME_JS_REFRESH_LONG
time_refresh_net = TIME_JS_REFRESH_NET
@login_required(login_url='/login/')
def getnetstat(request):
"""
Return netstat output
"""
try:
net_stat = get_netstat()
except Exception:
net_stat = None
data = json.dumps(net_stat)
response = HttpResponse()
response['Content-Type'] = "text/javascript"
response.write(data)
return response
@login_required(login_url='/login/')
def uptime(request):
"""
@ -49,6 +67,7 @@ def uptime(request):
response.write(data)
return response
@login_required(login_url='/login/')
def getdisk(request):
"""

Loading…
Cancel
Save