Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

docker: add not_running_unhealthy state #1160

Merged
merged 1 commit into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions modules/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ Labels per scope:
- global: no labels.
- container: container_name, image.

| Metric | Scope | Dimensions | Units |
|--------------------------------|:---------:|:------------------------------------------------------------:|:----------:|
| containers_state | global | running, paused, stopped | containers |
| containers_health_status | global | healthy, unhealthy, starting, no_healthcheck | containers |
| images | global | active, dangling | images |
| images_size | global | size | bytes |
| container_state | container | running, paused, exited, created, restarting, removing, dead | state |
| container_health_status | container | healthy, unhealthy, starting, no_healthcheck | status |
| container_writeable_layer_size | container | writeable_layer | size |
| Metric | Scope | Dimensions | Units |
|--------------------------------|:---------:|:-------------------------------------------------------------------:|:----------:|
| containers_state | global | running, paused, stopped | containers |
| containers_health_status | global | healthy, unhealthy, not_running_unhealthy, starting, no_healthcheck | containers |
| images | global | active, dangling | images |
| images_size | global | size | bytes |
| container_state | container | running, paused, exited, created, restarting, removing, dead | state |
| container_health_status | container | healthy, unhealthy, not_running_unhealthy, starting, no_healthcheck | status |
| container_writeable_layer_size | container | writeable_layer | size |

## Configuration

Expand Down
2 changes: 2 additions & 0 deletions modules/docker/charts.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ var (
Dims: module.Dims{
{ID: "containers_health_status_healthy", Name: "healthy"},
{ID: "containers_health_status_unhealthy", Name: "unhealthy"},
{ID: "containers_health_status_not_running_unhealthy", Name: "not_running_unhealthy"},
{ID: "containers_health_status_starting", Name: "starting"},
{ID: "containers_health_status_none", Name: "no_healthcheck"},
},
Expand Down Expand Up @@ -121,6 +122,7 @@ var (
Dims: module.Dims{
{ID: "container_%s_health_status_healthy", Name: "healthy"},
{ID: "container_%s_health_status_unhealthy", Name: "unhealthy"},
{ID: "container_%s_health_status_not_running_unhealthy", Name: "not_running_unhealthy"},
{ID: "container_%s_health_status_starting", Name: "starting"},
{ID: "container_%s_health_status_none", Name: "no_healthcheck"},
},
Expand Down
24 changes: 22 additions & 2 deletions modules/docker/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,25 @@ func (d *Docker) collectContainers(mx map[string]int64) error {

seen := make(map[string]bool)

for _, s := range containerHealthStatuses {
mx["containers_health_status_"+s] = 0
}
mx["containers_health_status_not_running_unhealthy"] = 0

for status, containers := range containerSet {
mx["containers_health_status_"+status] = int64(len(containers))
if status != types.Unhealthy {
mx["containers_health_status_"+status] = int64(len(containers))
}

for _, cntr := range containers {
if status == types.Unhealthy {
if cntr.State == "running" {
mx["containers_health_status_"+status] += 1
} else {
mx["containers_health_status_not_running_unhealthy"] += 1
}
}

if len(cntr.Names) == 0 {
continue
}
Expand All @@ -149,11 +164,16 @@ func (d *Docker) collectContainers(mx map[string]int64) error {
for _, s := range containerHealthStatuses {
mx[px+"health_status_"+s] = 0
}
mx[px+"health_status_not_running_unhealthy"] = 0
for _, s := range containerStates {
mx[px+"state_"+s] = 0
}

mx[px+"health_status_"+status] = 1
if status == types.Unhealthy && cntr.State != "running" {
mx[px+"health_status_not_running_unhealthy"] += 1
} else {
mx[px+"health_status_"+status] = 1
}
mx[px+"state_"+cntr.State] = 1
mx[px+"size_rw"] = cntr.SizeRw
mx[px+"size_root_fs"] = cntr.SizeRootFs
Expand Down
Loading