mirror of
https://github.com/HorlogeSkynet/archey4
synced 2024-11-24 04:00:10 +01:00
02ea37fbbf
This is a "bit more OOP" and easier to understand. + Unrelated change: Fix stupid range test I added to `Colors` -- has been bugging me since I noticed it :)
36 lines
1.0 KiB
Python
36 lines
1.0 KiB
Python
"""System load average detection module"""
|
|
|
|
import os
|
|
from contextlib import suppress
|
|
|
|
from archey.colors import Colors
|
|
from archey.entry import Entry
|
|
|
|
|
|
class LoadAverage(Entry):
|
|
"""System load average detection entry"""
|
|
|
|
_ICON = "\U000f051f" # md_timer_sand
|
|
_PRETTY_NAME = "Load Average"
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
|
|
with suppress(AttributeError):
|
|
self.value = os.getloadavg()
|
|
|
|
def __str__(self) -> str:
|
|
# DRY constant thresholds.
|
|
decimal_places = self.options.get("decimal_places", 2)
|
|
warning_threshold = self.options.get("warning_threshold", 1.0)
|
|
danger_threshold = self.options.get("danger_threshold", 2.0)
|
|
|
|
return " ".join(
|
|
[
|
|
str(Colors.get_level_color(load_avg, warning_threshold, danger_threshold))
|
|
+ str(round(load_avg, decimal_places))
|
|
+ str(Colors.CLEAR)
|
|
for load_avg in self.value
|
|
]
|
|
)
|