sleepguard.monitors package
Submodules
sleepguard.monitors.base module
- class sleepguard.monitors.base.UtilizationMonitor(poll_period: float, log_history_size: int, threshold: float, *args, **kwargs)[source]
Bases:
Thread,ABCA base class for all system utilization monitoring threads.
- Parameters:
poll_period – The number of seconds between logging the system resource.
log_history_size – The number of values to store in the resource utilization logs. The average utilization will be calculated from these values.
threshold – The value at which sleep will be inhibited if the average utilization value exceeds it.
- get_average_utilization() float[source]
Get the average utilization of the monitored resource over the
threshold_period.- Returns:
- abstract get_instantaneous_value() float[source]
Return the instantaneous value of the monitored system resource.
- Returns:
- is_above_threshold() bool[source]
Returns true if the value from
get_average_utilizationis above thethreshold.- Returns:
- property is_running: bool
Checks if the thread is running (not stopped).
- Returns:
- property is_stopped: bool
Checks if the thread is stopped.
- Returns:
- property poll_period: float
How often the value of the system resource is polled.
- Returns:
- property threshold: float
The value at which sleep will be inhibited if the average utilization value exceeds it.
- Returns:
sleepguard.monitors.cpu module
- class sleepguard.monitors.cpu.CpuLoadMonitor(poll_period: float, log_history_size: int, threshold: float, *args, **kwargs)[source]
Bases:
UtilizationMonitorKeeps track of the average CPU load over the given
threshold_period.- Parameters:
poll_period – The number of seconds between logging the system resource.
log_history_size – The number of values to store in the resource utilization logs. The average utilization will be calculated from these values.
threshold – The value at which sleep will be inhibited if the average utilization value exceeds it.
- class sleepguard.monitors.cpu.CpuUtilizationMonitor(poll_period: float, log_history_size: int, threshold: float, *args, **kwargs)[source]
Bases:
UtilizationMonitorKeeps track of the average CPU percent utilization over the given
threshold_period.- Parameters:
poll_period – The number of seconds between logging the system resource.
log_history_size – The number of values to store in the resource utilization logs. The average utilization will be calculated from these values.
threshold – The value at which sleep will be inhibited if the average utilization value exceeds it.
sleepguard.monitors.factory module
- class sleepguard.monitors.factory.UtilizationMonitorFactory[source]
Bases:
objectA factory class for creating
UtilizationMonitorinstances.- static from_criteria(criteria: MonitorCriteria, raise_on_error: bool = False) UtilizationMonitor | None[source]
Create an instance of a
UtilizationMonitorfrom the givencriteria.- Parameters:
criteria – The
MonitorCriteriato used to create the instance.raise_on_error – If
True, an exception will be raised if the instance cannot be created, for example an unsupported GPU is detected when using theGpuUtilizationMonitor. Otherwise,Noneis returned.
- Returns:
sleepguard.monitors.gpu module
- class sleepguard.monitors.gpu.GpuUtilizationMonitor(poll_period: float, log_history_size: int, threshold: float, *args, **kwargs)[source]
Bases:
UtilizationMonitorKeeps track of the average GPU percent utilization over the given
threshold_period.- Parameters:
poll_period – The number of seconds between logging the system resource.
log_history_size – The number of values to store in the resource utilization logs. The average utilization will be calculated from these values.
threshold – The value at which sleep will be inhibited if the average utilization value exceeds it.
sleepguard.monitors.net module
- class sleepguard.monitors.net.NetUtilizationMonitor(poll_period: float, log_history_size: int, threshold: float, *args, **kwargs)[source]
Bases:
UtilizationMonitorKeeps track of the average total number of bytes sent and received per second over the given
threshold_period.- Parameters:
poll_period – The number of seconds between logging the system resource.
log_history_size – The number of values to store in the resource utilization logs. The average utilization will be calculated from these values.
threshold – The value at which sleep will be inhibited if the average utilization value exceeds it.
Module contents
Utility methods and classes for monitoring system utilization.
- class sleepguard.monitors.MonitorCriteria(*args, **kwargs)[source]
Bases:
UserDictThe criteria used for monitoring a given system resource and determining if it should prevent the system from sleeping.
Note
This is implemented as a dictionary because
simple-parsingdoes not support lists of dataclasses.- as_kwargs() dict[str, int | float][source]
Return the criteria as
kwargssuitable for constructing aUtilizationMonitorinstance.- Returns:
- property log_history_size: int
- property poll_period: float
- property system_resource: Literal['cpu_load', 'cpu_util', 'gpu_util', 'net_util']
- property threshold: float
- sleepguard.monitors.SystemResource
The valid types of system resources to monitor.
alias of
Literal[‘cpu_load’, ‘cpu_util’, ‘gpu_util’, ‘net_util’]