diff --git a/main/views.py b/main/views.py index ad1d9ef..5878bd8 100755 --- a/main/views.py +++ b/main/views.py @@ -282,17 +282,32 @@ 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(): + try: + pipe = os.popen("netstat -tlnp|grep LISTEN|awk '{print $4, $5, $7}'") + data = pipe.read().strip().split('\n') + pipe.close() + data = [i.split(None, 3) for i in data] + except Exception, err: + data = str(err) + if data[0] == []: + data = [['No', 'data', 'available']] + #for i in data: + # temp = i.split() + # print temp[3] + temp[4] + return data @login_required(login_url='/login/') def getall(request): 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..f9bd6cd 100644 --- a/templates/main.html +++ b/templates/main.html @@ -42,6 +42,7 @@
  • RAM
  • Load
  • Users
  • +
  • Netstat
  • Network
  • Processes
  • @@ -250,32 +251,58 @@
    -
    -
    -
    -

    Online

    -
    -
    -
    - -
    - - - - - - - - - - -
    UserTTYLogged in from
    -
    - -
    - -
    - +
    +
    +
    +

    Online

    +
    +
    +
    + +
    + + + + + + + + + + +
    UserTTYLogged in from
    +
    + +
    + +
    + +
    +
    +
    +

    Netstat

    +
    +
    +
    + +
    + + + + + + + + + + +
    Local AddressForeign AddressPID/Program Name
    +
    + +
    + +
    +
    @@ -357,6 +384,7 @@ function get_os_data(url, element) { var dashboard = {}; + dashboard.getUptime = function() { get_os_data('/info/uptime/', "#get-uptime"); } @@ -380,6 +408,17 @@ dashboard.getUsers = function() { $("#get-users").html( tr ); }); } +dashboard.getNetstat = function() { + $.getJSON('/info/getnetstat/', function(data) { + var tr=''; + $.each( data, function( index, item){ + tr+=''+item[0]+''+item[1]+''+item[2]+''; + }) + tr+=''; + console.log(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(); }); diff --git a/usage/views.py b/usage/views.py index bdbbcb7..0a8a366 100755 --- a/usage/views.py +++ b/usage/views.py @@ -33,6 +33,18 @@ 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 + """ + net_stat = get_netstat() + 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): """