Add container health metrics to docker input (#3666)
This commit is contained in:
parent
4c9e9ac6f3
commit
286dcab4f9
|
@ -199,6 +199,9 @@ based on the availability of per-cpu stats on your system.
|
||||||
- network
|
- network
|
||||||
- docker_container_blkio specific:
|
- docker_container_blkio specific:
|
||||||
- device
|
- device
|
||||||
|
- docker_container_health specific:
|
||||||
|
- health_status
|
||||||
|
- failing_streak
|
||||||
- docker_swarm specific:
|
- docker_swarm specific:
|
||||||
- service_id
|
- service_id
|
||||||
- service_name
|
- service_name
|
||||||
|
|
|
@ -391,12 +391,13 @@ func (d *Docker) gatherContainer(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
info, err := d.client.ContainerInspect(ctx, container.ID)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error inspecting docker container: %s", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
// Add whitelisted environment variables to tags
|
// Add whitelisted environment variables to tags
|
||||||
if len(d.TagEnvironment) > 0 {
|
if len(d.TagEnvironment) > 0 {
|
||||||
info, err := d.client.ContainerInspect(ctx, container.ID)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Error inspecting docker container: %s", err.Error())
|
|
||||||
}
|
|
||||||
for _, envvar := range info.Config.Env {
|
for _, envvar := range info.Config.Env {
|
||||||
for _, configvar := range d.TagEnvironment {
|
for _, configvar := range d.TagEnvironment {
|
||||||
dock_env := strings.SplitN(envvar, "=", 2)
|
dock_env := strings.SplitN(envvar, "=", 2)
|
||||||
|
@ -408,6 +409,14 @@ func (d *Docker) gatherContainer(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if info.State.Health != nil {
|
||||||
|
healthfields := map[string]interface{}{
|
||||||
|
"health_status": info.State.Health.Status,
|
||||||
|
"failing_streak": info.ContainerJSONBase.State.Health.FailingStreak,
|
||||||
|
}
|
||||||
|
acc.AddFields("docker_container_health", healthfields, tags, time.Now())
|
||||||
|
}
|
||||||
|
|
||||||
gatherContainerStats(v, acc, tags, container.ID, d.PerDevice, d.Total, daemonOSType)
|
gatherContainerStats(v, acc, tags, container.ID, d.PerDevice, d.Total, daemonOSType)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -477,4 +477,12 @@ var containerInspect = types.ContainerJSON{
|
||||||
"PATH=/bin:/sbin",
|
"PATH=/bin:/sbin",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
ContainerJSONBase: &types.ContainerJSONBase{
|
||||||
|
State: &types.ContainerState{
|
||||||
|
Health: &types.Health{
|
||||||
|
FailingStreak: 1,
|
||||||
|
Status: "Unhealthy",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue