Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ualex73 committed Feb 27, 2021
2 parents 625cde6 + 52964ef commit 855ce60
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ monitor_docker:
| images | Number of images | - |
| state | Container state. This is created, restarting, running, removing, paused, exited or dead | - |
| status | Container status. E.g. Up 13 days, Up 5 hours, Exited (0) 11 hours ago | - |
| health | Container health if available | - |
| uptime | Container start time | - |
| image | Container image | - |
| cpu_percentage | CPU usage | % |
Expand Down
2 changes: 2 additions & 0 deletions custom_components/monitor_docker/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

CONTAINER_INFO_ALLINONE = "allinone"
CONTAINER_INFO_STATE = "state"
CONTAINER_INFO_HEALTH = "health"
CONTAINER_INFO_STATUS = "status"
CONTAINER_INFO_NETWORK_AVAILABLE = "network_available"
CONTAINER_INFO_UPTIME = "uptime"
Expand Down Expand Up @@ -63,6 +64,7 @@

CONTAINER_MONITOR_LIST = {
CONTAINER_INFO_STATE: ["State", None, "mdi:checkbox-marked-circle-outline", None],
CONTAINER_INFO_HEALTH: ["Health", None, "mdi:heart-pulse", None],
CONTAINER_INFO_STATUS: ["Status", None, "mdi:checkbox-marked-circle-outline", None],
CONTAINER_INFO_UPTIME: ["Up Time", "", "mdi:clock", "timestamp"],
CONTAINER_INFO_IMAGE: ["Image", None, "mdi:information-outline", None],
Expand Down
10 changes: 8 additions & 2 deletions custom_components/monitor_docker/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
CONTAINER_STATS_NETWORK_TOTAL_DOWN,
DOCKER_INFO_IMAGES,
CONTAINER_INFO_STATE,
CONTAINER_INFO_HEALTH,
CONTAINER_INFO_STATUS,
CONTAINER_INFO_UPTIME,
DOCKER_INFO_CONTAINER_RUNNING,
Expand Down Expand Up @@ -588,12 +589,17 @@ async def _run_container_info(self):

raw = await self._container.show()

self._info[CONTAINER_INFO_STATE] = raw["State"]["Status"]
self._info[CONTAINER_INFO_IMAGE] = raw["Config"]["Image"]
self._info[CONTAINER_INFO_STATE] = raw["State"]["Status"]
self._info[CONTAINER_INFO_IMAGE] = raw["Config"]["Image"]
self._info[CONTAINER_INFO_NETWORK_AVAILABLE] = (
False if raw["HostConfig"]["NetworkMode"] in ["host", "none"] else True
)

try:
self._info[CONTAINER_INFO_HEALTH] = raw["State"]["Health"]["Status"]
except:
self._info[CONTAINER_INFO_HEALTH] = "unknown"

# We only do a calculation of startedAt, because we use it twice
startedAt = parser.parse(raw["State"]["StartedAt"])

Expand Down
4 changes: 3 additions & 1 deletion custom_components/monitor_docker/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
CONTAINER_INFO_IMAGE,
CONTAINER_INFO_NETWORK_AVAILABLE,
CONTAINER_INFO_STATE,
CONTAINER_INFO_HEALTH,
CONTAINER_INFO_STATUS,
CONTAINER_INFO_UPTIME,
CONTAINER_MONITOR_LIST,
Expand Down Expand Up @@ -362,6 +363,7 @@ def event_callback(self, remove=False):
if cond in [
CONTAINER_INFO_STATUS,
CONTAINER_INFO_IMAGE,
CONTAINER_INFO_HEALTH,
CONTAINER_INFO_UPTIME,
]:
self._attributes[cond] = info.get(cond, None)
Expand All @@ -370,7 +372,7 @@ def event_callback(self, remove=False):
elif self._var_id == CONTAINER_INFO_STATUS:
state = info.get(CONTAINER_INFO_STATUS)
self._state_extra = info.get(CONTAINER_INFO_STATE)
elif self._var_id in [CONTAINER_INFO_STATE, CONTAINER_INFO_IMAGE]:
elif self._var_id in [CONTAINER_INFO_STATE, CONTAINER_INFO_IMAGE, CONTAINER_INFO_HEALTH]:
state = info.get(self._var_id)
elif info.get(CONTAINER_INFO_STATE) == "running":
if self._var_id in CONTAINER_MONITOR_LIST:
Expand Down
1 change: 1 addition & 0 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ monitor_docker:
| images | Number of images | - |
| state | Container state. This is created, restarting, running, removing, paused, exited or dead | - |
| status | Container status. E.g. Up 13 days, Up 5 hours, Exited (0) 11 hours ago | - |
| health | Container health if available | - |
| uptime | Container start time | - |
| image | Container image | - |
| cpu_percentage | CPU usage | % |
Expand Down

0 comments on commit 855ce60

Please sign in to comment.