2018-12-03 14:22:12 +00:00
|
|
|
#!/usr/bin/python
|
2018-12-02 23:43:08 +00:00
|
|
|
|
2018-12-03 14:22:12 +00:00
|
|
|
import multiprocessing
|
|
|
|
import os
|
2018-12-02 23:43:08 +00:00
|
|
|
|
2019-09-11 18:36:28 +00:00
|
|
|
from block import *
|
2018-12-03 14:22:12 +00:00
|
|
|
|
2019-09-11 18:36:28 +00:00
|
|
|
ICON = "\uf085"
|
2018-12-03 14:22:12 +00:00
|
|
|
|
|
|
|
|
2019-09-11 18:36:28 +00:00
|
|
|
class Load(Block):
|
2018-12-03 14:22:12 +00:00
|
|
|
|
2019-09-11 18:36:28 +00:00
|
|
|
def __init__(self, icon=None, icon_color=None):
|
|
|
|
super().__init__(icon, icon_color)
|
2018-12-03 14:22:12 +00:00
|
|
|
|
2019-09-11 18:36:28 +00:00
|
|
|
self.cores = multiprocessing.cpu_count()
|
2018-12-03 14:22:12 +00:00
|
|
|
|
2019-09-11 18:36:28 +00:00
|
|
|
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)
|
2018-12-03 14:22:12 +00:00
|
|
|
|
2019-09-11 18:36:28 +00:00
|
|
|
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()
|
2018-12-03 14:22:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|