csle_collector.docker_stats_manager package

Subpackages

Submodules

csle_collector.docker_stats_manager.docker_stats_manager module

class csle_collector.docker_stats_manager.docker_stats_manager.DockerStatsManagerServicer[source]

Bases: csle_collector.docker_stats_manager.docker_stats_manager_pb2_grpc.DockerStatsManagerServicer

gRPC server for managing a docker stats monitor server. Allows to start/stop the docker stats monitor remotely and also to query the state of the server.

getDockerStatsMonitorStatus(request: docker_stats_manager_pb2.GetDockerStatsMonitorStatusMsg, context: grpc.ServicerContext) docker_stats_manager_pb2.DockerStatsMonitorDTO[source]

Gets the state of the docker stats monitors

Parameters
  • request – the gRPC request

  • context – the gRPC context

Returns

a clients DTO with the state of the docker stats manager

get_docker_stats_monitor_threads() List[csle_collector.docker_stats_manager.threads.docker_stats_thread.DockerStatsThread][source]

Gets the list of Docker stats monitor threads

Returns

the list of Docker stats monitor threads

startDockerStatsMonitor(request: docker_stats_manager_pb2.StartDockerStatsMonitorMsg, context: grpc.ServicerContext) docker_stats_manager_pb2.DockerStatsMonitorDTO[source]

Starts a new docker stats monitor

Parameters
  • request – the gRPC request

  • context – the gRPC context

Returns

a clients DTO with the state of the docker stats monitor

stopDockerStatsMonitor(request: docker_stats_manager_pb2.StopDockerStatsMonitorMsg, context: grpc.ServicerContext)[source]

Stops the docker stats monitor server

Parameters
  • request – the gRPC request

  • context – the gRPC context

Returns

a clients DTO with the state of the docker stats monitor server

csle_collector.docker_stats_manager.docker_stats_manager.serve(port: int = 50046, log_dir: str = '/var/log/csle/', max_workers: int = 10, log_file_name: str = 'docker_stats_manager.log') None[source]

Starts the gRPC server for managing docker stats collection

Parameters
  • port – the port that the server will listen to

  • log_dir – the directory to write the log file

  • log_file_name – the file name of the log

  • max_workers – the maximum number of parallel gRPC workers

Returns

None

csle_collector.docker_stats_manager.docker_stats_manager_pb2 module

Generated protocol buffer code.

csle_collector.docker_stats_manager.docker_stats_manager_pb2_grpc module

Client and server classes corresponding to protobuf-defined services.

class csle_collector.docker_stats_manager.docker_stats_manager_pb2_grpc.DockerStatsManager[source]

Bases: object

Interface exported by the server

static getDockerStatsMonitorStatus(request, target, options=(), channel_credentials=None, call_credentials=None, insecure=False, compression=None, wait_for_ready=None, timeout=None, metadata=None)[source]
static startDockerStatsMonitor(request, target, options=(), channel_credentials=None, call_credentials=None, insecure=False, compression=None, wait_for_ready=None, timeout=None, metadata=None)[source]
static stopDockerStatsMonitor(request, target, options=(), channel_credentials=None, call_credentials=None, insecure=False, compression=None, wait_for_ready=None, timeout=None, metadata=None)[source]
class csle_collector.docker_stats_manager.docker_stats_manager_pb2_grpc.DockerStatsManagerServicer[source]

Bases: object

Interface exported by the server

getDockerStatsMonitorStatus(request, context)[source]

Missing associated documentation comment in .proto file.

startDockerStatsMonitor(request, context)[source]

Missing associated documentation comment in .proto file.

stopDockerStatsMonitor(request, context)[source]

Missing associated documentation comment in .proto file.

class csle_collector.docker_stats_manager.docker_stats_manager_pb2_grpc.DockerStatsManagerStub(channel)[source]

Bases: object

Interface exported by the server

csle_collector.docker_stats_manager.docker_stats_manager_pb2_grpc.add_DockerStatsManagerServicer_to_server(servicer, server)[source]

csle_collector.docker_stats_manager.docker_stats_util module

class csle_collector.docker_stats_manager.docker_stats_util.DockerStatsUtil[source]

Bases: object

Utility class for managing docker container statistics

static calculate_blkio_mb(stats_dict: Dict[str, Any]) Tuple[float, float][source]
Parameters

stats_dict – the stats dict from the Docker API

Returns

(read_mb, wrote_mb)

static calculate_cpu_percent(stats_dict: Dict[str, Any]) float[source]

Calculates the CPU utilization percentage

Parameters

stats_dict – the stats dict from the Docker API

Returns

the CPU percentage

static calculate_cpu_percent2(stats_dict: Dict[str, Any], previous_cpu: float, previous_system: float) Tuple[Union[float, Any], float, float][source]

Calculates the CPU utilization percentage when precpu is broken in later versions of Docker

Parameters
  • stats_dict – the stats dict from the Docker API

  • previous_cpu – previous cpu percentage

  • previous_system – previous system percentage

Returns

the CPU percentage

static calculate_network_mb(stats_dict: Dict[str, Any]) Tuple[float, float][source]
Parameters

stats_dict – the stats dict from the Docker API

Returns

(received_mb, transceived_mb)

static docker_stats_monitor_dto_empty() docker_stats_manager_pb2.DockerStatsMonitorDTO[source]
Returns

an empty DockerStatsMonitorDTO

static docker_stats_monitor_dto_from_dict(d: Dict[str, Any]) docker_stats_manager_pb2.DockerStatsMonitorDTO[source]

Converts a dict representation of a DockerStatsMonitorDTO to a DTO

Parameters

d – the dict to convert

Returns

the converted DTO

static docker_stats_monitor_dto_to_dict(docker_stats_monitor_dto: docker_stats_manager_pb2.DockerStatsMonitorDTO) Dict[str, Any][source]

Converts a docker_stats_monitor_dto to a dict

Parameters

docker_stats_monitor_dto – the dto to convert

Returns

a dict representation of the DTO

static graceful_chain_get(stats_dict: Dict[str, Any], *args, default=None)[source]

Wrapper to handle errors

Parameters
  • stats_dict – stats dict to handle

  • args – extra arguments

  • default – default return in case of errors

Returns

default or parsed value

static parse_stats(stats_dict: Dict[str, Any], container: str) csle_collector.docker_stats_manager.dao.docker_stats.DockerStats[source]

Parses a stats dict into a DockerStats object

Parameters
  • stats_dict – the dict to parse

  • container – the container that the stats concerns

Returns

the parsed DockerStats object

csle_collector.docker_stats_manager.query_docker_stats_manager module

csle_collector.docker_stats_manager.query_docker_stats_manager.get_docker_stats_manager_status(stub: csle_collector.docker_stats_manager.docker_stats_manager_pb2_grpc.DockerStatsManagerStub, timeout=60) docker_stats_manager_pb2.DockerStatsMonitorDTO[source]

Queries the docker stats manager for the status

Parameters
  • stub – the stub to send the remote gRPC to the server

  • timeout – the GRPC timeout (seconds)

Returns

a DockerStatsManagerDTO describing the status of the server

csle_collector.docker_stats_manager.query_docker_stats_manager.start_docker_stats_monitor(stub: csle_collector.docker_stats_manager.docker_stats_manager_pb2_grpc.DockerStatsManagerStub, emulation: str, execution_first_ip_octet: int, kafka_ip: str, stats_queue_maxsize: int, time_step_len_seconds: int, kafka_port: int, containers: List[docker_stats_manager_pb2.ContainerIp], timeout=30000) docker_stats_manager_pb2.DockerStatsMonitorDTO[source]

Sends a request to the docker stats manager to start a new monitor thread

Parameters
  • stub – the stub to send the remote gRPC to the server

  • emulation – the name of the emulation

  • execution_first_ip_octet – the first octet of the ip of the execution

  • kafka_ip – the ip of the Kafka server to push stats to

  • stats_queue_maxsize – the maximum size of the queue

:param the length of the period between pushing data to Kafka :param kafka_port: the port of the Kafka server :param containers: list of names and ips of containers to monitor :param timeout: the GRPC timeout (seconds) :return: a DockerStatsManagerDTO describing the status of the server

csle_collector.docker_stats_manager.query_docker_stats_manager.stop_docker_stats_monitor(stub: csle_collector.docker_stats_manager.docker_stats_manager_pb2_grpc.DockerStatsManagerStub, emulation: str, execution_first_ip_octet: int, timeout=30000) docker_stats_manager_pb2.DockerStatsMonitorDTO[source]

Sends a request to the docker stats manager to start a new monitor thread

Parameters
  • stub – the stub to send the remote gRPC to the server

  • emulation – the emulation for which the monitor should be stopped

  • execution_first_ip_octet – the first octet of the ip of the execution

  • timeout – the GRPC timeout (seconds)

Returns

a DockerStatsManagerDTO describing the status of the server

Module contents