Move load to block usage
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
36441150a8
commit
101fa626d8
1 changed files with 29 additions and 15 deletions
|
@ -3,28 +3,42 @@
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from block import *
|
||||||
|
|
||||||
def load_fmt(load):
|
ICON = "\uf085"
|
||||||
cores = multiprocessing.cpu_count()
|
|
||||||
color = '#ffffff'
|
|
||||||
|
|
||||||
if load > cores * 0.5:
|
|
||||||
color = '#FFD966'
|
|
||||||
|
|
||||||
if load > cores * 0.7:
|
class Load(Block):
|
||||||
color = '#dd0000'
|
|
||||||
|
|
||||||
return '<span color="{}">{:.2f}</span>'.format(color, load)
|
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():
|
def main():
|
||||||
load1, load5, load15 = os.getloadavg()
|
block = Load(ICON)
|
||||||
|
block.render()
|
||||||
print('\uf085 {}, {}, {}'.format(
|
|
||||||
load_fmt(load1),
|
|
||||||
load_fmt(load5),
|
|
||||||
load_fmt(load15),
|
|
||||||
))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in a new issue