Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
feat: Update docker container handler to include health status in stats
  • Loading branch information
mateuszdrab committed May 28, 2024
commit 437513ea725b58636c65246783be4cf958efc995
9 changes: 7 additions & 2 deletions container/docker/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ type dockerContainerHandler struct {
creationTime time.Time

// Metadata associated with the container.
envs map[string]string
labels map[string]string
envs map[string]string
labels map[string]string
healthStatus string

// Image name used for this container.
image string
Expand Down Expand Up @@ -178,6 +179,7 @@ func newDockerContainerHandler(
rootfsStorageDir: rootfsStorageDir,
envs: make(map[string]string),
labels: ctnr.Config.Labels,
healthStatus: ctnr.State.Health.Status,
includedMetrics: metrics,
zfsParent: zfsParent,
}
Expand Down Expand Up @@ -303,6 +305,9 @@ func (h *dockerContainerHandler) GetSpec() (info.ContainerSpec, error) {
// TODO(vmarmol): Get from libcontainer API instead of cgroup manager when we don't have to support older Dockers.
func (h *dockerContainerHandler) GetStats() (*info.ContainerStats, error) {
stats, err := h.libcontainerHandler.GetStats()

stats.Health.Status = h.healthStatus

if err != nil {
return stats, err
}
Expand Down
7 changes: 7 additions & 0 deletions info/v1/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,11 @@ type ProcessStats struct {
Ulimits []UlimitSpec `json:"ulimits,omitempty"`
}

type Health struct {
// Health status of the container
Status string `json:"status"`
}

type ContainerStats struct {
// The time of this stat point.
Timestamp time.Time `json:"timestamp"`
Expand Down Expand Up @@ -969,6 +974,8 @@ type ContainerStats struct {
CpuSet CPUSetStats `json:"cpuset,omitempty"`

OOMEvents uint64 `json:"oom_events,omitempty"`

Health Health `json:"health,omitempty"`
}

func timeEq(t1, t2 time.Time, tolerance time.Duration) bool {
Expand Down
18 changes: 18 additions & 0 deletions metrics/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,24 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
}}
},
},
{
name: "container_health_state",
help: "The result of the container's health check",
valueType: prometheus.GaugeValue,
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{{
// inline if to check if s.health.status = healthy
value: func(s *info.ContainerStats) float64 {
if s.Health.Status == "healthy" {
return 1
} else {
return 0
}
}(s),
timestamp: s.Timestamp,
}}
},
},
},
includedMetrics: includedMetrics,
opts: opts,
Expand Down