diff --git a/api/docker/snapshot.go b/api/docker/snapshot.go index 7d7ceea8e..0ab887373 100644 --- a/api/docker/snapshot.go +++ b/api/docker/snapshot.go @@ -3,6 +3,7 @@ package docker import ( "context" "log" + "strings" "time" "github.com/docker/docker/api/types" @@ -126,6 +127,8 @@ func snapshotContainers(snapshot *portainer.Snapshot, cli *client.Client) error runningContainers := 0 stoppedContainers := 0 + healthyContainers := 0 + unhealthyContainers := 0 stacks := make(map[string]struct{}) for _, container := range containers { if container.State == "exited" { @@ -134,6 +137,12 @@ func snapshotContainers(snapshot *portainer.Snapshot, cli *client.Client) error runningContainers++ } + if strings.Contains(container.Status, "(healthy)") { + healthyContainers++ + } else if strings.Contains(container.Status, "(unhealthy)") { + unhealthyContainers++ + } + for k, v := range container.Labels { if k == "com.docker.compose.project" { stacks[v] = struct{}{} @@ -143,6 +152,8 @@ func snapshotContainers(snapshot *portainer.Snapshot, cli *client.Client) error snapshot.RunningContainerCount = runningContainers snapshot.StoppedContainerCount = stoppedContainers + snapshot.HealthyContainerCount = healthyContainers + snapshot.UnhealthyContainerCount = unhealthyContainers snapshot.StackCount += len(stacks) snapshot.SnapshotRaw.Containers = containers return nil diff --git a/api/portainer.go b/api/portainer.go index 14a96799f..23b149c82 100644 --- a/api/portainer.go +++ b/api/portainer.go @@ -390,18 +390,20 @@ type ( // Snapshot represents a snapshot of a specific endpoint at a specific time Snapshot struct { - Time int64 `json:"Time"` - DockerVersion string `json:"DockerVersion"` - Swarm bool `json:"Swarm"` - TotalCPU int `json:"TotalCPU"` - TotalMemory int64 `json:"TotalMemory"` - RunningContainerCount int `json:"RunningContainerCount"` - StoppedContainerCount int `json:"StoppedContainerCount"` - VolumeCount int `json:"VolumeCount"` - ImageCount int `json:"ImageCount"` - ServiceCount int `json:"ServiceCount"` - StackCount int `json:"StackCount"` - SnapshotRaw SnapshotRaw `json:"SnapshotRaw"` + Time int64 `json:"Time"` + DockerVersion string `json:"DockerVersion"` + Swarm bool `json:"Swarm"` + TotalCPU int `json:"TotalCPU"` + TotalMemory int64 `json:"TotalMemory"` + RunningContainerCount int `json:"RunningContainerCount"` + StoppedContainerCount int `json:"StoppedContainerCount"` + HealthyContainerCount int `json:"HealthyContainerCount"` + UnhealthyContainerCount int `json:"UnhealthyContainerCount"` + VolumeCount int `json:"VolumeCount"` + ImageCount int `json:"ImageCount"` + ServiceCount int `json:"ServiceCount"` + StackCount int `json:"StackCount"` + SnapshotRaw SnapshotRaw `json:"SnapshotRaw"` } // SnapshotRaw represents all the information related to a snapshot as returned by the Docker API diff --git a/app/docker/filters/filters.js b/app/docker/filters/filters.js index 3fd65f22a..46bdd65f0 100644 --- a/app/docker/filters/filters.js +++ b/app/docker/filters/filters.js @@ -248,6 +248,22 @@ angular.module('portainer.docker') }).length; }; }) +.filter('healthycontainers', function () { + 'use strict'; + return function healthyContainersFilter(containers) { + return containers.filter(function (container) { + return container.Status === 'healthy'; + }).length; + } +}) +.filter('unhealthycontainers', function () { + 'use strict'; + return function unhealthyContainersFilter(containers) { + return containers.filter(function (container) { + return container.Status === 'unhealthy'; + }).length; + } +}) .filter('imagestotalsize', function () { 'use strict'; return function (images) { diff --git a/app/docker/views/dashboard/dashboard.html b/app/docker/views/dashboard/dashboard.html index 89cee5867..b40e9bc62 100644 --- a/app/docker/views/dashboard/dashboard.html +++ b/app/docker/views/dashboard/dashboard.html @@ -109,9 +109,13 @@
-
-
{{ containers | runningcontainers }} running
-
{{ containers | stoppedcontainers }} stopped
+
+
{{ containers | runningcontainers }} running
+
{{ containers | stoppedcontainers }} stopped
+
+
+
{{ containers | healthycontainers }} healthy
+
{{ containers | unhealthycontainers }} unhealthy
{{ containers.length }}
{{ containers.length === 1 ? 'Container' : 'Containers' }}
diff --git a/app/portainer/components/endpoint-list/endpoint-item/endpointItem.html b/app/portainer/components/endpoint-list/endpoint-item/endpointItem.html index 3e15875ba..5060848a0 100644 --- a/app/portainer/components/endpoint-list/endpoint-item/endpointItem.html +++ b/app/portainer/components/endpoint-list/endpoint-item/endpointItem.html @@ -51,8 +51,11 @@ {{ $ctrl.model.Snapshots[0].RunningContainerCount + $ctrl.model.Snapshots[0].StoppedContainerCount }} {{ $ctrl.model.Snapshots[0].RunningContainerCount + $ctrl.model.Snapshots[0].StoppedContainerCount === 1 ? 'container' : 'containers' }} - - {{ $ctrl.model.Snapshots[0].RunningContainerCount }} - {{ $ctrl.model.Snapshots[0].StoppedContainerCount }} + {{ $ctrl.model.Snapshots[0].RunningContainerCount }} + {{ $ctrl.model.Snapshots[0].StoppedContainerCount }} + / + {{ $ctrl.model.Snapshots[0].HealthyContainerCount }} + {{ $ctrl.model.Snapshots[0].UnhealthyContainerCount }}