|
|
@ -20,16 +20,16 @@ |
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
|
# SOFTWARE. |
|
|
# SOFTWARE. |
|
|
|
|
|
|
|
|
import platform, os, multiprocessing, json |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import platform |
|
|
|
|
|
import os |
|
|
|
|
|
import multiprocessing |
|
|
from datetime import timedelta |
|
|
from datetime import timedelta |
|
|
|
|
|
|
|
|
from django.contrib.auth.decorators import login_required |
|
|
from django.contrib.auth.decorators import login_required |
|
|
from django.core import serializers |
|
|
|
|
|
from django.shortcuts import render_to_response |
|
|
from django.shortcuts import render_to_response |
|
|
from django.http import HttpResponseRedirect, HttpResponse |
|
|
|
|
|
|
|
|
from django.http import HttpResponseRedirect |
|
|
from django.template import RequestContext |
|
|
from django.template import RequestContext |
|
|
from django.utils.translation import ugettext_lazy as _ |
|
|
|
|
|
|
|
|
|
|
|
from pydash.settings import TIME_JS_REFRESH, TIME_JS_REFRESH_LONG, TIME_JS_REFRESH_NET, VERSION |
|
|
from pydash.settings import TIME_JS_REFRESH, TIME_JS_REFRESH_LONG, TIME_JS_REFRESH_NET, VERSION |
|
|
|
|
|
|
|
|
time_refresh = TIME_JS_REFRESH |
|
|
time_refresh = TIME_JS_REFRESH |
|
|
@ -37,6 +37,7 @@ time_refresh_long = TIME_JS_REFRESH_LONG |
|
|
time_refresh_net = TIME_JS_REFRESH_NET |
|
|
time_refresh_net = TIME_JS_REFRESH_NET |
|
|
version = VERSION |
|
|
version = VERSION |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required(login_url='/login/') |
|
|
@login_required(login_url='/login/') |
|
|
def index(request): |
|
|
def index(request): |
|
|
""" |
|
|
""" |
|
|
@ -50,6 +51,7 @@ def index(request): |
|
|
def chunks(get, n): |
|
|
def chunks(get, n): |
|
|
return [get[i:i + n] for i in range(0, len(get), n)] |
|
|
return [get[i:i + n] for i in range(0, len(get), n)] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_uptime(): |
|
|
def get_uptime(): |
|
|
""" |
|
|
""" |
|
|
Get uptime |
|
|
Get uptime |
|
|
@ -82,7 +84,7 @@ def get_ipaddress(): |
|
|
data1 = pipe.read().strip().split('\n') |
|
|
data1 = pipe.read().strip().split('\n') |
|
|
pipe.close() |
|
|
pipe.close() |
|
|
if len(data1) == 2: |
|
|
if len(data1) == 2: |
|
|
data1.append('unavailable', 'unavailable') |
|
|
|
|
|
|
|
|
data1.append('unavailable') |
|
|
if len(data1) == 3: |
|
|
if len(data1) == 3: |
|
|
data1.append('unavailable') |
|
|
data1.append('unavailable') |
|
|
data1[0] = i |
|
|
data1[0] = i |
|
|
@ -97,6 +99,7 @@ def get_ipaddress(): |
|
|
|
|
|
|
|
|
return data |
|
|
return data |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_cpus(): |
|
|
def get_cpus(): |
|
|
""" |
|
|
""" |
|
|
Get the number of CPUs and model/type |
|
|
Get the number of CPUs and model/type |
|
|
@ -120,6 +123,7 @@ def get_cpus(): |
|
|
|
|
|
|
|
|
return data |
|
|
return data |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_users(): |
|
|
def get_users(): |
|
|
""" |
|
|
""" |
|
|
Get the current logged in users |
|
|
Get the current logged in users |
|
|
@ -139,6 +143,7 @@ def get_users(): |
|
|
|
|
|
|
|
|
return data |
|
|
return data |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_traffic(request): |
|
|
def get_traffic(request): |
|
|
""" |
|
|
""" |
|
|
Get the traffic for the specified interface |
|
|
Get the traffic for the specified interface |
|
|
@ -167,6 +172,7 @@ def get_traffic(request): |
|
|
|
|
|
|
|
|
return data |
|
|
return data |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_platform(): |
|
|
def get_platform(): |
|
|
""" |
|
|
""" |
|
|
Get the OS name, hostname and kernel |
|
|
Get the OS name, hostname and kernel |
|
|
@ -185,6 +191,7 @@ def get_platform(): |
|
|
|
|
|
|
|
|
return data |
|
|
return data |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_disk(): |
|
|
def get_disk(): |
|
|
""" |
|
|
""" |
|
|
Get disk usage |
|
|
Get disk usage |
|
|
@ -201,6 +208,7 @@ def get_disk(): |
|
|
|
|
|
|
|
|
return data |
|
|
return data |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_disk_rw(): |
|
|
def get_disk_rw(): |
|
|
""" |
|
|
""" |
|
|
Get the disk reads and writes |
|
|
Get the disk reads and writes |
|
|
@ -233,6 +241,7 @@ def get_disk_rw(): |
|
|
|
|
|
|
|
|
return data |
|
|
return data |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_mem(): |
|
|
def get_mem(): |
|
|
""" |
|
|
""" |
|
|
Get memory usage |
|
|
Get memory usage |
|
|
@ -257,6 +266,7 @@ def get_mem(): |
|
|
|
|
|
|
|
|
return data |
|
|
return data |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_cpu_usage(): |
|
|
def get_cpu_usage(): |
|
|
""" |
|
|
""" |
|
|
Get the CPU usage and running processes |
|
|
Get the CPU usage and running processes |
|
|
@ -300,12 +310,15 @@ def get_load(): |
|
|
|
|
|
|
|
|
return data |
|
|
return data |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_netstat(): |
|
|
def get_netstat(): |
|
|
""" |
|
|
""" |
|
|
Get ports and applications |
|
|
Get ports and applications |
|
|
""" |
|
|
""" |
|
|
try: |
|
|
try: |
|
|
pipe = os.popen("ss -tnp | grep ESTAB | awk '{print $4, $5}'| sed 's/::ffff://g' | awk -F: '{print $1, $2}' | awk 'NF > 0' | sort -n | uniq -c") |
|
|
|
|
|
|
|
|
pipe = os.popen( |
|
|
|
|
|
"ss -tnp | grep ESTAB | awk '{print $4, $5}'| sed 's/::ffff://g' | awk -F: '{print $1, $2}' " |
|
|
|
|
|
"| awk 'NF > 0' | sort -n | uniq -c") |
|
|
data = pipe.read().strip().split('\n') |
|
|
data = pipe.read().strip().split('\n') |
|
|
pipe.close() |
|
|
pipe.close() |
|
|
|
|
|
|
|
|
@ -319,9 +332,7 @@ def get_netstat(): |
|
|
|
|
|
|
|
|
@login_required(login_url='/login/') |
|
|
@login_required(login_url='/login/') |
|
|
def getall(request): |
|
|
def getall(request): |
|
|
|
|
|
|
|
|
return render_to_response('main.html', {'time_refresh': time_refresh, |
|
|
return render_to_response('main.html', {'time_refresh': time_refresh, |
|
|
'time_refresh_long': time_refresh_long, |
|
|
'time_refresh_long': time_refresh_long, |
|
|
'time_refresh_net': time_refresh_net, |
|
|
'time_refresh_net': time_refresh_net, |
|
|
'version': version |
|
|
|
|
|
}, context_instance=RequestContext(request)) |
|
|
|
|
|
|
|
|
'version': version}, context_instance=RequestContext(request)) |