frobar: Add load provider

This commit is contained in:
Geoffrey Frogeye 2024-06-17 19:31:16 +02:00
parent d6d3df65df
commit 42034eb5d8
Signed by: geoffrey
GPG key ID: C72403E7F82E6AD8
3 changed files with 22 additions and 4 deletions

View file

@ -39,6 +39,7 @@ def run():
DANGER_THEME = 1
CRITICAL_THEME = 0
Bar.addSectionAll(CpuProvider(), BarGroupType.RIGHT)
Bar.addSectionAll(LoadProvider(), BarGroupType.RIGHT)
Bar.addSectionAll(RamProvider(), BarGroupType.RIGHT)
Bar.addSectionAll(TemperatureProvider(), BarGroupType.RIGHT)
Bar.addSectionAll(BatteryProvider(), BarGroupType.RIGHT)

View file

@ -92,7 +92,7 @@ class AlertingSection(StatefulSection):
class CpuProvider(AlertingSection, PeriodicUpdater):
NUMBER_STATES = 3
ICON = ""
ICON = ""
def fetcher(self):
percent = psutil.cpu_percent(percpu=False)
@ -108,6 +108,24 @@ class CpuProvider(AlertingSection, PeriodicUpdater):
PeriodicUpdater.__init__(self)
self.changeInterval(1)
class LoadProvider(AlertingSection, PeriodicUpdater):
NUMBER_STATES = 3
ICON = ""
def fetcher(self):
load = os.getloadavg()
self.updateLevel(load[0])
if self.state >= 2:
return " ".join(f"{load[i]:.2f}" for i in range(3))
elif self.state >= 1:
return f"{load[0]:.2f}"
def __init__(self, theme=None):
AlertingSection.__init__(self, theme)
PeriodicUpdater.__init__(self)
self.changeInterval(5)
self.warningThresold = 5
self.dangerThresold = 10
class RamProvider(AlertingSection, PeriodicUpdater):
"""
@ -115,7 +133,7 @@ class RamProvider(AlertingSection, PeriodicUpdater):
"""
NUMBER_STATES = 4
ICON = ""
ICON = ""
def fetcher(self):
mem = psutil.virtual_memory()

View file

@ -4,7 +4,7 @@
programs.powerline-go = {
enable = true;
modules = [ "user" "host" "venv" "cwd" "perms" "nix-shell" "git" ];
modulesRight = [ "jobs" "exit" "duration" "load" ];
modulesRight = [ "jobs" "exit" "duration" ];
settings = {
colorize-hostname = true;
hostname-only-if-ssh = true;
@ -20,4 +20,3 @@
};
};
}
# TODO Replace load with a frobar indicator