diff --git a/main/views.py b/main/views.py index 4724a13..61122f4 100755 --- a/main/views.py +++ b/main/views.py @@ -178,21 +178,50 @@ def get_mem(): return data +#def getcpu_usage(): +# try: +# pipe = os.popen("ps aux |" + "awk {'sum+=$3;print sum'} |" + "tail -n 1") +# data = pipe.read().strip() +# pipe.close() + +# cpu_free = (100 - float(data)) +# cpu_used = {'free': cpu_free, 'used': float(data)} +# data = cpu_used + +# except Exception,err: +# data = str(err) +# +# return data + + def get_cpu_usage(): try: - pipe = os.popen("ps aux |" + "awk {'sum+=$3;print sum'} |" + "tail -n 1") - data = pipe.read().strip() + pipe = os.popen("ps aux --sort -%cpu,-rss") + data = pipe.read().strip().split('\n') pipe.close() - - cpu_free = (100 - float(data)) - cpu_used = {'free': cpu_free, 'used': float(data)} + + usage = [i.split(None, 10) for i in data] + del usage[0] + + total_usage = [] + + for element in usage: + usage_cpu = element[2] + total_usage.append(usage_cpu) + + #del total_usage[0] + total_usage = sum(float(i) for i in total_usage) + + total_free = (100 - float(total_usage)) + + cpu_used = {'free': total_free, 'used': float(total_usage), 'all': usage} + data = cpu_used except Exception,err: data = str(err) return data - def get_load(): try: @@ -214,5 +243,6 @@ def getall(request): 'getip': get_ipaddress(), 'gettraffic': get_traffic('eth0'), 'getusers': get_users(), + 'getcpuusage': get_cpu_usage(), 'time_refresh': time_refresh }, context_instance=RequestContext(request)) diff --git a/pydash/settings.py b/pydash/settings.py index df8ca70..084f28f 100644 --- a/pydash/settings.py +++ b/pydash/settings.py @@ -21,7 +21,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(__file__)) 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 +DEBUG = True TEMPLATE_DEBUG = True diff --git a/templates/main.html b/templates/main.html index 6c97120..5480950 100644 --- a/templates/main.html +++ b/templates/main.html @@ -221,9 +221,7 @@
- - -
+ {% include 'processes.html' %}
diff --git a/templates/processes.html b/templates/processes.html new file mode 100644 index 0000000..1de018b --- /dev/null +++ b/templates/processes.html @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + {% for data in getcpuusage.all %} + {% for line in data %} + {% cycle '' '' '' '' '' '' '' '' '' '' ''%} + + {% cycle '' '' '' '' '' '' '' '' '' '' '' %} + {% endfor %} + {% endfor %} + +
UserPid%Cpu%MemVszRssTtyStatStartTimeCommand
{{line}}