cfg/.config/i3blocks/load
Knut Ahlers 101fa626d8
Move load to block usage
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2019-09-12 16:14:28 +02:00

45 lines
825 B
Python
Executable file

#!/usr/bin/python
import multiprocessing
import os
from block import *
ICON = "\uf085"
class Load(Block):
def __init__(self, icon=None, icon_color=None):
super().__init__(icon, icon_color)
self.cores = multiprocessing.cpu_count()
def load_fmt(self, load):
color = '#ffffff'
if load > self.cores * 0.5:
color = '#FFD966'
if load > self.cores * 0.7:
color = '#dd0000'
return self.color_text('{:.2f}'.format(load), color=color)
def execute(self):
load1, load5, load15 = os.getloadavg()
return ', '.join([
self.load_fmt(load1),
self.load_fmt(load5),
self.load_fmt(load15),
])
def main():
block = Load(ICON)
block.render()
if __name__ == '__main__':
main()