Reference¶
docker2mqtt package.
ContainerEventStateType = Literal['on', 'off']
module-attribute
¶
Container event state
ContainerEventStatusType = Literal['paused', 'running', 'stopped', 'destroyed', 'created']
module-attribute
¶
Container event docker status
Docker2Mqtt
¶
docker2mqtt class.
Attributes:
Name | Type | Description |
---|---|---|
version |
str
|
The version of docker2mqtt |
cfg |
Docker2MqttConfig
|
The config for docker2mqtt |
b_stats |
bool
|
Activate the stats |
b_events |
bool
|
Activate the events |
docker_events |
Queue[str]
|
Queue with docker events |
docker_stats |
Queue[str]
|
Queue with docker stats |
known_event_containers |
dict[str, ContainerEvent]
|
The dict with the known container events |
known_stat_containers |
dict[str, ContainerStatsRef]
|
The dict with the known container stats references |
last_stat_containers |
dict[str, ContainerStats | dict[str, Any]]
|
The dict with the last container stats |
mqtt |
Client
|
The mqtt client |
docker_events_t |
Thread
|
The thread to collect events from docker |
docker_stats_t |
Thread
|
The thread to collect stats from docker |
docker_version |
str
|
The docker version |
discovery_binary_sensor_topic |
str
|
Topic template for a binary sensor |
discovery_sensor_topic |
str
|
Topic template for a nary sensor |
status_topic |
str
|
Topic template for a status value |
version_topic |
str
|
Topic template for a version value |
stats_topic |
str
|
Topic template for stats |
events_topic |
str
|
Topic template for an events |
do_not_exit |
bool
|
Prevent exit from within docker2mqtt, when handled outside |
Initialize the docker2mqtt.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cfg
|
Docker2MqttConfig
|
The configuration object for docker2mqtt |
required |
do_not_exit
|
bool
|
Prevent exit from within docker2mqtt, when handled outside |
False
|
Source code in docker2mqtt/docker2mqtt.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
|
__del__
¶
loop
¶
Start the loop.
Raises:
Type | Description |
---|---|
Docker2MqttEventsException
|
If anything goes wrong in the processing of the events |
Docker2MqttStatsException
|
If anything goes wrong in the processing of the stats |
Docker2MqttException
|
If anything goes wrong outside of the known exceptions |
Source code in docker2mqtt/docker2mqtt.py
loop_busy
¶
Start the loop (blocking).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raise_known_exceptions
|
bool
|
Should any known processing exception be raised or ignored |
False
|
Raises:
Type | Description |
---|---|
Docker2MqttEventsException
|
If anything goes wrong in the processing of the events |
Docker2MqttStatsException
|
If anything goes wrong in the processing of the stats |
Docker2MqttException
|
If anything goes wrong outside of the known exceptions |
Source code in docker2mqtt/docker2mqtt.py
Docker2MqttConfigException
¶
Bases: Docker2MqttException
Config exception occurred.
Docker2MqttConnectionException
¶
Bases: Docker2MqttException
Connection exception occurred.
Docker2MqttEventsException
¶
Bases: Docker2MqttException
Events processing exception occurred.
Docker2MqttStatsException
¶
Bases: Docker2MqttException
Stats processing exception occurred.
ContainerDeviceEntry
¶
ContainerEntry
¶
Bases: TypedDict
A container entry object for discovery in home assistant.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name of the sensor to display in home assistant |
unique_id |
str
|
The unique id of the sensor in home assistant |
icon |
str | None
|
The icon of the sensor to display |
availability_topic |
str
|
The topic to check the availability of the sensor |
payload_available |
str
|
The payload of availability_topic of the sensor when available |
payload_unavailable |
The payload of availability_topic of the sensor when unavailable |
|
state_topic |
str
|
The topic containing all information for the state of the sensor |
value_template |
str
|
The jinja2 template to extract the state value from the state_topic for the sensor |
unit_of_measurement |
str | None
|
The unit of measurement of the sensor |
payload_on |
str | None
|
When a binary sensor: The value of extracted state of the sensor to be considered 'on' |
payload_off |
str | None
|
When a binary sensor: The value of extracted state of the sensor to be considered 'off' |
device |
ContainerDeviceEntry
|
The device the sensor is attributed to |
device_class |
str | None
|
The device class of the sensor |
state_topic |
str
|
The topic containing all information for the attributes of the sensor |
qos |
int
|
The QOS of the discovery message |
ContainerEvent
¶
Bases: TypedDict
A container event object to send to an mqtt topic.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name of the container |
image |
str
|
The image the container is running |
status |
ContainerEventStatusType
|
The docker status the container is in |
state |
ContainerEventStateType
|
The state of the container |
ContainerStats
¶
Bases: TypedDict
A container stats object to send to an mqtt topic.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name of the container |
host |
str
|
The docker host |
memory |
str
|
Human-readable memory information from docker |
memoryused |
float
|
Used memory in MB |
memorylimit |
float
|
Memory limit in MB |
netio |
str
|
Human-readable network information from docker |
netinput |
float
|
Network input in MB |
netinputrate |
float
|
Network input rate in MB/s |
netoutput |
float
|
Network output in MB |
netoutputrate |
float
|
Network output rate in MB/s |
blockinput |
float
|
Block (to disk) input in MB |
blockinputrate |
float
|
Block (to disk) input rate in MB/s |
blockoutput |
float
|
Block (to disk) output in MB |
blockoutputrate |
float
|
Block (to disk) output rate in MB/s |
cpu |
float
|
The cpu usage by the container in cpu-% (ex.: a docker with 4 cores has 400% cpu available) |
ContainerStatsRef
¶
Docker2MqttConfig
¶
Bases: TypedDict
A config object.
Attributes:
Name | Type | Description |
---|---|---|
log_level |
str
|
Log verbosity |
destroyed_container_ttl |
int
|
How long, in seconds, before destroyed containers are removed from Home Assistant. Containers won't be removed if the service is restarted before the TTL expires. |
homeassistant_prefix |
str
|
MQTT discovery topic prefix |
docker2mqtt_hostname |
str
|
A descriptive name for the docker being monitored |
mqtt_client_id |
str
|
Client Id for MQTT broker client |
mqtt_user |
str
|
Username for MQTT broker authentication |
mqtt_password |
str
|
Password for MQTT broker authentication |
mqtt_host |
str
|
Hostname or IP address of the MQTT broker |
mqtt_port |
int
|
Port or IP address of the MQTT broker |
mqtt_timeout |
int
|
Timeout for MQTT messages |
mqtt_topic_prefix |
str
|
MQTT topic prefix |
mqtt_qos |
int
|
QOS for standard MQTT messages |
container_whitelist |
list[str]
|
Whitelist the containers to monitor, if empty, everything is monitored. The entries are either match as literal strings or as regex. |
container_blacklist |
list[str]
|
Blacklist the containers to monitor, takes priority over whitelist. The entries are either match as literal strings or as regex. |
enable_events |
bool
|
Flag to enable event monitoring |
enable_stats |
bool
|
Flag to enable stat monitoring |
stats_record_seconds |
int
|
Interval every how many seconds the stats are published via MQTT |
clean_for_discovery
¶
Cleanup a typed dict for home assistant discovery, which is quite picky and does not like empty of None values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
val
|
ContainerEntry
|
The TypedDict to cleanup |
required |
Returns:
Type | Description |
---|---|
dict
|
The cleaned dict |