|
|
@ -25,40 +25,28 @@ def index(request): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def chunks(get, n): |
|
|
def chunks(get, n): |
|
|
#for i in xrange(0, len(get), n): |
|
|
|
|
|
#yield l[i:i+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 |
|
|
""" |
|
|
""" |
|
|
#if not request.user.is_authenticated(): |
|
|
|
|
|
# return HttpResponseRedirect('/login') |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
try: |
|
|
with open('/proc/uptime', 'r') as f: |
|
|
with open('/proc/uptime', 'r') as f: |
|
|
uptime_seconds = float(f.readline().split()[0]) |
|
|
uptime_seconds = float(f.readline().split()[0]) |
|
|
uptime_time = str(timedelta(seconds = uptime_seconds)) |
|
|
uptime_time = str(timedelta(seconds = uptime_seconds)) |
|
|
#return uptime_time |
|
|
|
|
|
data = uptime_time.split('.', 1)[0] |
|
|
data = uptime_time.split('.', 1)[0] |
|
|
|
|
|
|
|
|
except Exception,err: |
|
|
except Exception,err: |
|
|
data = str(err) |
|
|
data = str(err) |
|
|
|
|
|
|
|
|
#response = HttpResponse() |
|
|
|
|
|
#response['Content-Type'] = "text/javascript" |
|
|
|
|
|
#response.write(data) |
|
|
|
|
|
|
|
|
|
|
|
return data |
|
|
return data |
|
|
#print data |
|
|
|
|
|
#return render_to_response('main.html', {'getuptime': data, 'time_refresh': time_refresh}, context_instance=RequestContext(request)) |
|
|
|
|
|
|
|
|
|
|
|
def get_hostname(): |
|
|
def get_hostname(): |
|
|
""" |
|
|
""" |
|
|
Get the hostname |
|
|
Get the hostname |
|
|
""" |
|
|
""" |
|
|
#if not request.user.is_authenticated(): |
|
|
|
|
|
# return HttpResponseRedirect('/login') |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
try: |
|
|
data = socket.gethostname() |
|
|
data = socket.gethostname() |
|
|
@ -66,11 +54,7 @@ def get_hostname(): |
|
|
except Exception,err: |
|
|
except Exception,err: |
|
|
data = str(err) |
|
|
data = str(err) |
|
|
|
|
|
|
|
|
#response = HttpResponse() |
|
|
|
|
|
#response['Content-Type'] = "text/javascript" |
|
|
|
|
|
#response.write(data) |
|
|
|
|
|
return data |
|
|
return data |
|
|
#return render_to_response('main.html', {'gethostname': data}, context_instance=RequestContext(request)) |
|
|
|
|
|
|
|
|
|
|
|
def get_ipaddress(): |
|
|
def get_ipaddress(): |
|
|
""" |
|
|
""" |
|
|
@ -82,15 +66,6 @@ def get_ipaddress(): |
|
|
pipe.close() |
|
|
pipe.close() |
|
|
|
|
|
|
|
|
data = [n for n in data if not n.startswith(('lo', '127'))] |
|
|
data = [n for n in data if not n.startswith(('lo', '127'))] |
|
|
#x=len(data) |
|
|
|
|
|
|
|
|
|
|
|
#data1 = list(range(x)) |
|
|
|
|
|
|
|
|
|
|
|
#data = dict(zip(data1,data)) |
|
|
|
|
|
#data = data1 |
|
|
|
|
|
|
|
|
|
|
|
#data = chunks(data, 2) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
itf = dict(zip(*[iter(data)] * 2)) |
|
|
itf = dict(zip(*[iter(data)] * 2)) |
|
|
ips = {'interface': itf, 'itfip': data} |
|
|
ips = {'interface': itf, 'itfip': data} |
|
|
@ -111,15 +86,11 @@ def get_traffic(request): |
|
|
data = pipe.read().strip().split(':',1)[-1] |
|
|
data = pipe.read().strip().split(':',1)[-1] |
|
|
pipe.close() |
|
|
pipe.close() |
|
|
|
|
|
|
|
|
#data = [n for n in data if not n.startswith(('lo'))] |
|
|
|
|
|
data = data.split() |
|
|
data = data.split() |
|
|
|
|
|
|
|
|
traffic_in = int(data[0]) |
|
|
traffic_in = int(data[0]) |
|
|
traffic_out = int(data[1]) |
|
|
traffic_out = int(data[1]) |
|
|
|
|
|
|
|
|
#percent = (100 - ((freemem * 100) / allmem)) |
|
|
|
|
|
#usage = (allmem - freemem) |
|
|
|
|
|
|
|
|
|
|
|
all_traffic = {'traffic_in': traffic_in, 'traffic_out': traffic_out} |
|
|
all_traffic = {'traffic_in': traffic_in, 'traffic_out': traffic_out} |
|
|
|
|
|
|
|
|
data = all_traffic |
|
|
data = all_traffic |
|
|
@ -135,7 +106,6 @@ def get_platform(): |
|
|
""" |
|
|
""" |
|
|
try: |
|
|
try: |
|
|
data = " ".join(platform.linux_distribution()) |
|
|
data = " ".join(platform.linux_distribution()) |
|
|
# + " " + platform.system() + " " + platform.release() |
|
|
|
|
|
|
|
|
|
|
|
except Exception,err: |
|
|
except Exception,err: |
|
|
data = str(err) |
|
|
data = str(err) |
|
|
@ -147,26 +117,13 @@ def get_disk(): |
|
|
Get disk usage |
|
|
Get disk usage |
|
|
""" |
|
|
""" |
|
|
try: |
|
|
try: |
|
|
#data = commands.getoutput("df -Ph | column -t") |
|
|
|
|
|
pipe = os.popen("df -Ph | " + "grep -v Filesystem | " + "awk '{print $1, $2, $3, $4, $5, $6}'") |
|
|
pipe = os.popen("df -Ph | " + "grep -v Filesystem | " + "awk '{print $1, $2, $3, $4, $5, $6}'") |
|
|
data = pipe.read().strip().split() |
|
|
data = pipe.read().strip().split() |
|
|
pipe.close() |
|
|
pipe.close() |
|
|
|
|
|
|
|
|
#x=len(data) |
|
|
|
|
|
|
|
|
|
|
|
#data1 = list(range(x)) |
|
|
|
|
|
|
|
|
|
|
|
#data = dict(zip(data1,data)) |
|
|
|
|
|
#data = data1 |
|
|
|
|
|
|
|
|
|
|
|
#data = chunks(data, 1) |
|
|
|
|
|
#data = simplejson.dumps(data) |
|
|
|
|
|
#data = serializers.serialize('json', data) |
|
|
|
|
|
|
|
|
|
|
|
except Exception,err: |
|
|
except Exception,err: |
|
|
data = str(err) |
|
|
data = str(err) |
|
|
|
|
|
|
|
|
#eturn HttpResponse(data, mimetype="application/json") |
|
|
|
|
|
return data |
|
|
return data |
|
|
|
|
|
|
|
|
def get_mem(): |
|
|
def get_mem(): |
|
|
@ -202,16 +159,10 @@ def getall(request): |
|
|
if not request.user.is_authenticated(): |
|
|
if not request.user.is_authenticated(): |
|
|
return HttpResponseRedirect('/login') |
|
|
return HttpResponseRedirect('/login') |
|
|
|
|
|
|
|
|
#getuptime = get_uptime() |
|
|
|
|
|
#global getuptime |
|
|
|
|
|
|
|
|
|
|
|
#gethostname = get_hostname(request) |
|
|
|
|
|
|
|
|
|
|
|
return render_to_response('main.html', {'getuptime': get_uptime(), |
|
|
return render_to_response('main.html', {'getuptime': get_uptime(), |
|
|
'gethostname': get_hostname(), |
|
|
'gethostname': get_hostname(), |
|
|
'getplatform': get_platform(), |
|
|
'getplatform': get_platform(), |
|
|
'getdisk': get_disk(), |
|
|
'getdisk': get_disk(), |
|
|
'getip': get_ipaddress(), |
|
|
'getip': get_ipaddress(), |
|
|
#'gettraffic': get_traffic(), |
|
|
|
|
|
'time_refresh': time_refresh |
|
|
'time_refresh': time_refresh |
|
|
}, context_instance=RequestContext(request)) |
|
|
}, context_instance=RequestContext(request)) |