cpu load trigger: made cooldown period configuraable

This commit is contained in:
2025-03-11 19:38:56 +01:00
parent c077476e0b
commit 7d826b97af
3 changed files with 9 additions and 4 deletions
+1
View File
@@ -49,6 +49,7 @@
<oneMinuteLoadThreshold>0.3</oneMinuteLoadThreshold> <oneMinuteLoadThreshold>0.3</oneMinuteLoadThreshold>
<fiveMinuteLoadThreshold>0.2</fiveMinuteLoadThreshold> <fiveMinuteLoadThreshold>0.2</fiveMinuteLoadThreshold>
<tenMinuteLoadThreshold>0.1</tenMinuteLoadThreshold> <tenMinuteLoadThreshold>0.1</tenMinuteLoadThreshold>
<cooldownPeriodInMinutes>3</cooldownPeriodInMinutes>
</customConfig> </customConfig>
</trigger> </trigger>
</triggers> </triggers>
@@ -8,7 +8,7 @@ from datetime import datetime, timedelta
class CpuLoadTrigger(Trigger): class CpuLoadTrigger(Trigger):
def __init__(self, _config: Config) -> None: def __init__(self, _config: Config) -> None:
super().__init__(_config) super().__init__(_config)
self.timestamp_last_governor_change = datetime.now() - timedelta(minutes=10) self.timestamp_last_governor_change = datetime.now() - timedelta(minutes=self.cooldown_period_in_minutes + 1)
@cached_property @cached_property
def one_minute_load_threshold(self) -> float: def one_minute_load_threshold(self) -> float:
@@ -26,6 +26,10 @@ class CpuLoadTrigger(Trigger):
def threshold(self) -> tuple[float, float, float]: def threshold(self) -> tuple[float, float, float]:
return self.one_minute_load_threshold, self.five_minute_load_threshold, self.ten_minute_load_threshold return self.one_minute_load_threshold, self.five_minute_load_threshold, self.ten_minute_load_threshold
@cached_property
def cooldown_period_in_minutes(self) -> float:
return float(self.config.custom_config['cooldownPeriodInMinutes'])
@property @property
def current_load(self) -> tuple[float, float, float]: def current_load(self) -> tuple[float, float, float]:
_current_load = getloadavg() _current_load = getloadavg()
@@ -48,8 +52,8 @@ class CpuLoadTrigger(Trigger):
self.timestamp_last_governor_change = current_time self.timestamp_last_governor_change = current_time
elif current_active and not new_active: elif current_active and not new_active:
if (current_time - timedelta(minutes=5)) < self.timestamp_last_governor_change: if (current_time - timedelta(minutes=self.cooldown_period_in_minutes)) < self.timestamp_last_governor_change:
self.log.info("cooldown period, staying on governor: %s", self.governor.name) self.log.info("cooldown period, staying on governor: %s, current load: %s", self.governor.name, self.current_load)
return return
self.log.info( self.log.info(
+1 -1
View File
@@ -1,6 +1,6 @@
[project] [project]
name = "cpu_governor_auto_adjust" name = "cpu_governor_auto_adjust"
version = "0.1.41" version = "0.1.42"
description = "This application has been developed to automatically change cpu governor based on certain triggers." description = "This application has been developed to automatically change cpu governor based on certain triggers."
authors = [ authors = [
{ name = "Martin Reurekas", email = "martin@semrks.nl" } { name = "Martin Reurekas", email = "martin@semrks.nl" }