@@ -68,9 +68,8 @@ type dockerContainerHandler struct {
6868 creationTime time.Time
6969
7070 // Metadata associated with the container.
71- envs map [string ]string
72- labels map [string ]string
73- healthStatus string
71+ envs map [string ]string
72+ labels map [string ]string
7473
7574 // Image name used for this container.
7675 image string
@@ -93,6 +92,9 @@ type dockerContainerHandler struct {
9392 reference info.ContainerReference
9493
9594 libcontainerHandler * containerlibcontainer.Handler
95+
96+ // the docker client is needed to inspect the container and get the health status
97+ client docker.APIClient
9698}
9799
98100var _ container.ContainerHandler = & dockerContainerHandler {}
@@ -201,10 +203,7 @@ func newDockerContainerHandler(
201203 labels : ctnr .Config .Labels ,
202204 includedMetrics : metrics ,
203205 zfsParent : zfsParent ,
204- }
205- // Health status may be nil if no health check is configured
206- if ctnr .State .Health != nil {
207- handler .healthStatus = ctnr .State .Health .Status
206+ client : client ,
208207 }
209208 // Timestamp returned by Docker is in time.RFC3339Nano format.
210209 handler .creationTime , err = time .Parse (time .RFC3339Nano , ctnr .Created )
@@ -328,13 +327,20 @@ func (h *dockerContainerHandler) GetSpec() (info.ContainerSpec, error) {
328327// TODO(vmarmol): Get from libcontainer API instead of cgroup manager when we don't have to support older Dockers.
329328func (h * dockerContainerHandler ) GetStats () (* info.ContainerStats , error ) {
330329 stats , err := h .libcontainerHandler .GetStats ()
331-
332- stats .Health .Status = h .healthStatus
333-
334330 if err != nil {
335331 return stats , err
336332 }
337333
334+ // We assume that if Inspect fails then the container is not known to docker.
335+ ctnr , err := h .client .ContainerInspect (context .Background (), h .reference .Id )
336+ if err != nil {
337+ return nil , fmt .Errorf ("failed to inspect container %q: %v" , h .reference .Id , err )
338+ }
339+
340+ if ctnr .State .Health != nil {
341+ stats .Health .Status = ctnr .State .Health .Status
342+ }
343+
338344 // Get filesystem stats.
339345 err = FsStats (stats , h .machineInfoFactory , h .includedMetrics , h .storageDriver ,
340346 h .fsHandler , h .fsInfo , h .poolName , h .rootfsStorageDir , h .zfsParent )
0 commit comments