Browse Source

fix traffic reading if under 100MB

windows
Florian N 12 years ago
parent
commit
5c91047cf4
  1. 2
      README.md
  2. 14
      main/views.py

2
README.md

@ -8,7 +8,7 @@ The dashboard is built using only Python libraries available in the main Python
Current dependencies: Current dependencies:
- >= Django 1.6.1
- == Django 1.6.1
[View Demo](http://pydash-test.hostechs.com) [View Demo](http://pydash-test.hostechs.com)

14
main/views.py

@ -130,6 +130,11 @@ def get_traffic(request):
data = pipe.read().strip().split(':',1)[-1] data = pipe.read().strip().split(':',1)[-1]
pipe.close() pipe.close()
if type(data[0]) is str:
pipe = os.popen("cat /proc/net/dev |" + "grep " + request + "| awk '{print $2, $10}'")
data = pipe.read().strip().split(':',1)[-1]
pipe.close()
data = data.split() data = data.split()
traffic_in = int(data[0]) traffic_in = int(data[0])
@ -173,6 +178,9 @@ def get_disk():
return data return data
def get_mem(): def get_mem():
"""
Get memory usage
"""
try: try:
pipe = os.popen("free -tmo | " + "grep 'Mem' | " + "awk '{print $2,$4}'") pipe = os.popen("free -tmo | " + "grep 'Mem' | " + "awk '{print $2,$4}'")
data = pipe.read().strip().split() data = pipe.read().strip().split()
@ -194,6 +202,9 @@ def get_mem():
return data return data
def get_cpu_usage(): def get_cpu_usage():
"""
Get the CPU usage and running processes
"""
try: try:
pipe = os.popen("ps aux --sort -%cpu,-rss") pipe = os.popen("ps aux --sort -%cpu,-rss")
data = pipe.read().strip().split('\n') data = pipe.read().strip().split('\n')
@ -223,6 +234,9 @@ def get_cpu_usage():
return data return data
def get_load(): def get_load():
"""
Get load average
"""
try: try:
data = os.getloadavg()[0] data = os.getloadavg()[0]
except Exception, err: except Exception, err:

Loading…
Cancel
Save