Added support for checing load on MacOS

This commit is contained in:
2017-02-14 09:59:05 +01:00
parent 8464abd097
commit c77a3b4c12

View File

@@ -1,11 +1,20 @@
#!/usr/bin/env python3
from subprocess import check_output
from re import findall
from platform import system
def load():
arpOutput = check_output("cat /proc/loadavg", shell=True)
arpOutput = arpOutput.decode()
print(findall('[0-9]{1,2}[\.][0-9]{2}', arpOutput))
sysName = system()
if sysName == 'Linux':
arpOutput = check_output("cat /proc/loadavg", shell=True)
arpOutput = arpOutput.decode()
return findall('[0-9]{1,2}[\.][0-9]{2}', arpOutput)
elif sysName == 'Darwin':
arpOutput = check_output("uptime", shell=True)
arpOutput = arpOutput.decode()
return findall('[0-9]{1,2}[\.][0-9]{2}', arpOutput)
return {"Error": "Running OS does not supported load."}
if __name__ == '__main__':
load()
print(load())