StatsCollector

class shell_logger.stats_collector.StatsCollector(interval, _)[source]

Bases: object

Collect statistics while running command in the shell.

Provides an interface for the ShellLogger to run commands while collecting various system statistics.

Initialize the StatsCollector object.

Set the poling interval, and create the process for collecting the statistics.

Parameters:

interval (float) – How long to sleep between collecting statistics.

Note

A SyncManager will be supplied at the second argument for any subclasses.

abstract collect()[source]

Instantaneously collect a statistic.

This is meant to be called repeatedly after some time interval.

Raises:

AbstractMethod – This must be overridden by subclasses.

finish()[source]

Stop collecting statistics.

Terminate the infinite loop that’s collecting the statistics, and then return the unproxied statistics.

loop()[source]

Loop while collecting statistics.

Infinitely loop, collecting statistics, until the subprocess is terminated.

start()[source]

Start a subprocess.

Poll at a certain interval for certain statistics.

stat_name = 'undefined'
static subclass(stats_collector_subclass)[source]

Mark a class as being a supported stats collector.

This is a class decorator that adds to a list of supported StatsCollector classes for the stats_collectors() factory method.

subclasses = [<class 'shell_logger.stats_collector.DiskStatsCollector'>, <class 'shell_logger.stats_collector.CPUStatsCollector'>, <class 'shell_logger.stats_collector.MemoryStatsCollector'>]
abstract unproxied_stats()[source]

Convert to standard Python data types.

Convert from Python’s Manager’s data structures to base Python data structures.

Raises:

AbstractMethod – This must be overridden by subclasses.

shell_logger.stats_collector.stats_collectors()[source]

Generate stats collectors.

A factory method that returns a list of any subclasses of StatsCollector that have the @StatsCollector.subclass decorator applied to them.

Parameters:

**kwargs – Any supported arguments of the StatsCollector subclasses.

Return type:

List[StatsCollector]

Returns:

A collection of instances of StatsCollector subclasses.

DiskStatsCollector

class shell_logger.stats_collector.DiskStatsCollector(interval, manager)[source]

Bases: StatsCollector

A null disk statistics collector for when data aren’t available.

A phony DiskStatsCollector used when psutil is unavailable. This collects no disk statistics.

Initialize the object via the parent’s constructor.

Parameters:
  • interval (float) – How many seconds to sleep between polling.

  • manager (SyncManager) – The multiprocessing manager used to control the process used to collect the statistics.

collect()[source]

Don’t collect any disk statistics.

Return type:

None

stat_name = 'disk'
unproxied_stats()[source]

If asked for the disk statistics, don’t provide any.

Return type:

None

Returns:

None

CPUStatsCollector

class shell_logger.stats_collector.CPUStatsCollector(interval, manager)[source]

Bases: StatsCollector

A null CPU statistics collector for when data aren’t available.

A phony CPUStatsCollector used when psutil is unavailable. This collects no CPU statistics.

Initialize the object via the parent’s constructor.

Parameters:
  • interval (float) – How many seconds to sleep between polling.

  • manager (SyncManager) – The multiprocessing manager used to control the process used to collect the statistics.

collect()[source]

Don’t collect any CPU statistics.

Return type:

None

stat_name = 'cpu'
unproxied_stats()[source]

If asked for CPU statistics, don’t provide any.

Return type:

None

Returns:

None

MemoryStatsCollector

class shell_logger.stats_collector.MemoryStatsCollector(interval, manager)[source]

Bases: StatsCollector

A null memory stats collector for when data aren’t available.

A phony MemoryStatsCollector used when psutil is unavailable. This collects no memory statistics.

Initialize the object via the parent’s constructor.

Parameters:
  • interval (float) – How many seconds to sleep between polling.

  • manager (SyncManager) – The multiprocessing manager used to control the process used to collect the statistics.

collect()[source]

Don’t collect any memory statistics.

Return type:

None

stat_name = 'memory'
unproxied_stats()[source]

If asked for memory statistics, don’t provide any.

Return type:

None

Returns:

None