diff --git a/v1/cpuTemp.py b/v1/cpuTemp.py new file mode 100755 index 0000000..b6e1eb5 --- /dev/null +++ b/v1/cpuTemp.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# @Author: KevinMidboe +# @Date: 2017-01-28 13:56:48 +# @Last Modified by: KevinMidboe +# @Last Modified time: 2017-01-28 13:58:35 + +from pyspectator.processor import Cpu +from time import sleep + +cpu = Cpu(monitoring_latency=1) +with cpu: + for _ in range(8): + cpu.load, cpu.temperature + sleep(1.1) \ No newline at end of file diff --git a/v1/diskusage.py b/v1/diskusage.py new file mode 100755 index 0000000..08f1322 --- /dev/null +++ b/v1/diskusage.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# @Author: KevinMidboe +# @Date: 2017-01-28 10:54:06 +# @Last Modified by: KevinMidboe +# @Last Modified time: 2017-01-28 13:23:07 + +from os import statvfs + +def sizeof(num, suffix='B'): + for unit in ['','K','M','G','T','P','E','Z']: + if abs(num) < 1000.0: + return "%3.1f%s%s" % (num, unit, suffix) + num /= 1000.0 + return "%.1f%s%s" % (num, 'Y', suffix) + +def diskUsage(path='/'): + s = statvfs(path) + byteLeft = s.f_bavail * s.f_frsize + byteTotal = s.f_blocks * s.f_frsize + byteUsed = byteTotal-byteLeft + + return { 'left':sizeof(byteLeft), 'used':sizeof(byteUsed), 'total':sizeof(byteTotal) } + +if __name__=="__main__": + n = diskUsage('/') + print(n) \ No newline at end of file diff --git a/v1/uptime.py b/v1/uptime.py new file mode 100755 index 0000000..eadcfa7 --- /dev/null +++ b/v1/uptime.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# @Author: KevinMidboe +# @Date: 2017-01-27 19:48:42 +# @Last Modified by: KevinMidboe +# @Last Modified time: 2017-01-28 13:30:19 + +from psutil import boot_time +from time import time + +def timeSinceBoot(): + # Use psutil 'boot_time' to get seconds since start + bootTime = boot_time() + # Use 'time()' to get seconds currently + currTime = time() + delta = int(currTime-bootTime) + + # Return in day format + if delta >= 86400: + # TODO error handling + rt = int(delta/86400) + if rt is 1: + return str(rt)+' day' + else: + return str(rt)+' days' + + # Return in hour format + elif delta < 86400 and delta >= 0: + # TODO error handling + hours = (delta)//3600 + minutes = (delta - hours*3600)//60 + rt = '%02d' % hours +':'+ '%02d' % minutes + return rt + else: + # Throw error + return 'Null' + +if __name__=="__main__": + print(timeSinceBoot()) \ No newline at end of file