mirror of
https://github.com/KevinMidboe/Node-Com-Handler.git
synced 2025-10-29 09:40:27 +00:00
Better error messages
This commit is contained in:
15
status/load.py
Normal file → Executable file
15
status/load.py
Normal file → Executable file
@@ -1,20 +1,25 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Author: KevinMidboe
|
||||
# @Date: 2017-02-15 23:45:16
|
||||
# @Last Modified by: KevinMidboe
|
||||
# @Last Modified time: 2017-02-18 11:42:42
|
||||
|
||||
from subprocess import check_output
|
||||
from re import findall
|
||||
from platform import system
|
||||
|
||||
def load():
|
||||
sysName = system()
|
||||
sysName = system() # Get system name
|
||||
if sysName == 'Linux':
|
||||
arpOutput = check_output("cat /proc/loadavg", shell=True)
|
||||
elif sysName == 'Darwin':
|
||||
elif sysName == 'Darwin': # macOS
|
||||
arpOutput = check_output("uptime", shell=True)
|
||||
else:
|
||||
return {"Error": "Running OS does not supported load."}
|
||||
return {"errors": "Running OS does not supported load."}
|
||||
|
||||
arpOutput = arpOutput.decode()
|
||||
return findall('[0-9]{1,2}[\.][0-9]{2}', arpOutput)
|
||||
|
||||
return {"loads": findall('[0-9]{1,2}[\.][0-9]{2}', arpOutput)}
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(load())
|
||||
|
||||
Reference in New Issue
Block a user