From 4192d739fd06dabfc64fd91d96cc57e4d97a3a18 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Wed, 15 Feb 2017 10:24:44 +0100 Subject: [PATCH] Shortend down on load.py and made it logically faster. --- status/load.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 status/load.py diff --git a/status/load.py b/status/load.py new file mode 100644 index 0000000..4f642d2 --- /dev/null +++ b/status/load.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +from subprocess import check_output +from re import findall +from platform import system + +def load(): + sysName = system() + if sysName == 'Linux': + arpOutput = check_output("cat /proc/loadavg", shell=True) + elif sysName == 'Darwin': + arpOutput = check_output("uptime", shell=True) + else: + return {"Error": "Running OS does not supported load."} + + arpOutput = arpOutput.decode() + return findall('[0-9]{1,2}[\.][0-9]{2}', arpOutput) + + +if __name__ == '__main__': + print(load())