feat(dashboard): add health status to home page and dashboard (#3489)

* feat(dashboard): add health status to home page and dashboard

* fix(dashboard): code review updates, using builtin for substring search
This commit is contained in:
Mike Church
2020-02-04 19:59:29 +01:00
committed by GitHub
parent cc8d3c8639
commit 6f59f130a1
5 changed files with 53 additions and 17 deletions

View File

@@ -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