Browse Source

change in cpu data processing

windows
Florian N 12 years ago
parent
commit
c0aee80182
  1. 42
      main/views.py
  2. 2
      pydash/settings.py
  3. 4
      templates/main.html
  4. 26
      templates/processes.html

42
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))

2
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

4
templates/main.html

@ -221,9 +221,7 @@
</div>
<!-- /widget-header -->
<div class="widget-content">
<table id="ps_dashboard" class="table table-hover table-condensed table-bordered" >
</table>
{% include 'processes.html' %}
</div>
<!-- /widget-content -->
</div>

26
templates/processes.html

@ -0,0 +1,26 @@
<table class="table table-hover table-condensed table-bordered">
<thead>
<tr>
<th>User</th>
<th>Pid</th>
<th>%Cpu</th>
<th>%Mem</th>
<th>Vsz</th>
<th>Rss</th>
<th>Tty</th>
<th>Stat</th>
<th>Start</th>
<th>Time</th>
<th>Command</th>
</tr>
</thead>
<tbody>
{% for data in getcpuusage.all %}
{% for line in data %}
{% cycle '<tr>' '' '' '' '' '' '' '' '' '' ''%}
<td>{{line}}</td>
{% cycle '' '' '' '' '' '' '' '' '' '' '</tr>' %}
{% endfor %}
{% endfor %}
</tbody>
</table>
Loading…
Cancel
Save