platypush.plugins.system

class platypush.plugins.system.SystemPlugin(**kwargs)[source]

Plugin to get system info.

Requires:

  • py-cpuinfo (pip install py-cpuinfo) for CPU model and info.
  • psutil (pip install psutil) for CPU load and stats.
connected_users() → platypush.message.response.system.ConnectedUserResponseList[source]

Get the list of connected users. :return: List of platypush.message.response.system.ConnectUserResponse.

cpu_frequency(per_cpu: bool = False) → Union[platypush.message.response.system.CpuFrequencyResponse, platypush.message.response.system.CpuResponseList][source]

Get CPU stats.

Parameters:per_cpu – Get per-CPU stats (default: False).
Returns:platypush.message.response.system.CpuFrequencyResponse
cpu_info() → platypush.message.response.system.CpuInfoResponse[source]

Get CPU info. :return: platypush.message.response.system.CpuInfoResponse

cpu_percent(per_cpu: bool = False, interval: Optional[float] = None) → Union[float, List[float]][source]

Get the CPU load percentage.

Parameters:
  • per_cpu – Get per-CPU stats (default: False).
  • interval – When interval is 0.0 or None compares system CPU times elapsed since last call or module import, returning immediately (non blocking). That means the first time this is called it will return a meaningless 0.0 value which you should ignore. In this case is recommended for accuracy that this function be called with at least 0.1 seconds between calls.
Returns:

float if per_cpu=False, list[float] otherwise.

cpu_stats() → platypush.message.response.system.CpuStatsResponse[source]

Get CPU stats. :return: platypush.message.response.system.CpuStatsResponse

cpu_times(per_cpu=False, percent=False) → Union[platypush.message.response.system.CpuTimesResponse, platypush.message.response.system.CpuResponseList][source]

Get the CPU times stats.

Parameters:
  • per_cpu – Get per-CPU stats (default: False).
  • percent – Get the stats in percentage (default: False).
Returns:

platypush.message.response.system.CpuTimesResponse

disk_io_counters(disk: Optional[str] = None, per_disk: bool = False) → Union[platypush.message.response.system.DiskIoCountersResponse, platypush.message.response.system.DiskResponseList][source]

Get the I/O counter stats for the mounted disks.

Parameters:
  • disk – Select the stats for a specific disk (e.g. ‘sda1’). Default: get stats for all mounted disks.
  • per_disk – Return the stats per disk (default: False).
Returns:

platypush.message.response.system.DiskIoCountersResponse or list of platypush.message.response.system.DiskIoCountersResponse.

disk_partitions() → platypush.message.response.system.DiskResponseList[source]

Get the list of partitions mounted on the system. :return: list of platypush.message.response.system.DiskPartitionResponse

disk_usage(path: Optional[str] = None) → Union[platypush.message.response.system.DiskUsageResponse, platypush.message.response.system.DiskResponseList][source]

Get the usage of a mounted disk.

Parameters:path – Path where the device is mounted (default: get stats for all mounted devices).
Returns:platypush.message.response.system.DiskUsageResponse or list of platypush.message.response.system.DiskUsageResponse.
kill(pid: int)[source]

Kill a process. :param pid: Process PID.

load_avg() → List[float][source]

Get the average load as a vector that represents the load within the last 1, 5 and 15 minutes.

mem_swap() → platypush.message.response.system.SwapMemoryUsageResponse[source]

Get the current virtual memory usage stats. :return: list of platypush.message.response.system.SwapMemoryUsageResponse

mem_virtual() → platypush.message.response.system.VirtualMemoryUsageResponse[source]

Get the current virtual memory usage stats. :return: list of platypush.message.response.system.VirtualMemoryUsageResponse

net_addresses(nic: Optional[str] = None) → Union[platypush.message.response.system.NetworkAddressResponse, platypush.message.response.system.NetworkResponseList][source]

Get address info associated to the network interfaces.

Parameters:nic – Select the stats for a specific network device (e.g. ‘eth0’). Default: get stats for all NICs.
Returns:platypush.message.response.system.NetworkAddressResponse or list of platypush.message.response.system.NetworkAddressResponse.
net_connections(type: Optional[str] = None) → Union[platypush.message.response.system.NetworkConnectionResponse, platypush.message.response.system.NetworkResponseList][source]

Get the list of active network connections. On macOS this function requires root privileges.

Parameters:type

Connection type to filter. Supported types:

Kind Value Connections using
inet inet4 inet6 tcp tcp4 tcp6 udp udp4 udp6 unix all IPv4 and IPv6 IPv4 IPv6 TCP TCP over IPv4 TCP over IPv6 UDP UDP over IPv4 UDP over IPv6 UNIX socket (both UDP and TCP protocols) the sum of all the possible families and protocols
Returns:List of platypush.message.response.system.NetworkConnectionResponse.
net_io_counters(nic: Optional[str] = None, per_nic: bool = False) → Union[platypush.message.response.system.NetworkIoCountersResponse, platypush.message.response.system.NetworkResponseList][source]

Get the I/O counters stats for the network interfaces.

Parameters:
  • nic – Select the stats for a specific network device (e.g. ‘eth0’). Default: get stats for all NICs.
  • per_nic – Return the stats broken down per interface (default: False).
Returns:

platypush.message.response.system.NetIoCountersResponse or list of platypush.message.response.system.NetIoCountersResponse.

net_stats(nic: Optional[str] = None) → Union[platypush.message.response.system.NetworkInterfaceStatsResponse, platypush.message.response.system.NetworkResponseList][source]

Get stats about the network interfaces.

Parameters:nic – Select the stats for a specific network device (e.g. ‘eth0’). Default: get stats for all NICs.
Returns:platypush.message.response.system.NetworkInterfaceStatsResponse or list of platypush.message.response.system.NetworkInterfaceStatsResponse.
pid_exists(pid: int) → bool[source]
Parameters:pid – Process PID.
Returns:True if the process exists, False otherwise.
processes(filter: Optional[str] = '') → platypush.message.response.system.ProcessResponseList[source]

Get the list of running processes.

Parameters:filter – Filter the list by name.
Returns:List of platypush.message.response.system.ProcessResponse.
resume(pid: int)[source]

Resume a process. :param pid: Process PID.

sensors_battery() → platypush.message.response.system.SensorBatteryResponse[source]

Get stats from the battery sensor. :return: List of platypush.message.response.system.SensorFanResponse.

sensors_fan(sensor: Optional[str] = None) → platypush.message.response.system.SensorResponseList[source]

Get stats from the fan sensors.

Parameters:sensor – Select the sensor name.
Returns:List of platypush.message.response.system.SensorFanResponse.
sensors_temperature(sensor: Optional[str] = None, fahrenheit: bool = False) → Union[platypush.message.response.system.SensorTemperatureResponse, List[platypush.message.response.system.SensorTemperatureResponse], Dict[str, Union[platypush.message.response.system.SensorTemperatureResponse, List[platypush.message.response.system.SensorTemperatureResponse]]]][source]

Get stats from the temperature sensors.

Parameters:
  • sensor – Select the sensor name.
  • fahrenheit – Return the temperature in Fahrenheit (default: Celsius).
suspend(pid: int)[source]

Suspend a process. :param pid: Process PID.

terminate(pid: int)[source]

Terminate a process. :param pid: Process PID.

wait(pid: int, timeout: int = None)[source]

Wait for a process to terminate.

Parameters:
  • pid – Process PID.
  • timeout – Timeout in seconds (default: None).