kernel
2019-01-05 11:35:03 +08:00
我的桌面 load 太高提示的小程序:
#!/usr/bin/env python
import subprocess
import re
import os
import sys
import datetime
uptime_output = subprocess.check_output(['uptime']).decode()
loads = tuple(map(float, re.search(r'load average: ([.\d]+), ([.\d]+), ([.\d]+)', uptime_output).groups()))
print('system load:', loads)
throttle = float(sys.argv[1])
if all(load > throttle for load in loads):
os.system('notify-send -i emblem-system "Load Alert" "[{}] {}"'.format(
datetime.datetime.now().strftime('%H:%M:%S'), loads))