From 54b1009a9f0a2232e1c1b8456df48c614251f1ec Mon Sep 17 00:00:00 2001 From: Joshua Powers Date: Mon, 24 Jul 2023 01:25:31 -0600 Subject: [PATCH] fix(inputs.docker): Add restart count (#13646) --- plugins/inputs/docker/docker.go | 9 ++--- plugins/inputs/docker/docker_test.go | 54 +++++++++++++++------------- 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/plugins/inputs/docker/docker.go b/plugins/inputs/docker/docker.go index a91769106..bf6bbe8e5 100644 --- a/plugins/inputs/docker/docker.go +++ b/plugins/inputs/docker/docker.go @@ -515,10 +515,11 @@ func (d *Docker) gatherContainerInspect( if info.State != nil { tags["container_status"] = info.State.Status statefields := map[string]interface{}{ - "oomkilled": info.State.OOMKilled, - "pid": info.State.Pid, - "exitcode": info.State.ExitCode, - "container_id": container.ID, + "oomkilled": info.State.OOMKilled, + "pid": info.State.Pid, + "exitcode": info.State.ExitCode, + "restart_count": info.RestartCount, + "container_id": container.ID, } finished, err := time.Parse(time.RFC3339, info.State.FinishedAt) diff --git a/plugins/inputs/docker/docker_test.go b/plugins/inputs/docker/docker_test.go index bd2f0b056..198f924fe 100644 --- a/plugins/inputs/docker/docker_test.go +++ b/plugins/inputs/docker/docker_test.go @@ -753,12 +753,13 @@ func TestContainerStatus(t *testing.T) { "source": "e2173b9478a6", }, map[string]interface{}{ - "oomkilled": false, - "pid": 1234, - "exitcode": 0, - "container_id": "e2173b9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296b7dfb", - "started_at": time.Date(2018, 6, 14, 5, 48, 53, 266176036, time.UTC).UnixNano(), - "uptime_ns": int64(3 * time.Minute), + "oomkilled": false, + "pid": 1234, + "restart_count": 0, + "exitcode": 0, + "container_id": "e2173b9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296b7dfb", + "started_at": time.Date(2018, 6, 14, 5, 48, 53, 266176036, time.UTC).UnixNano(), + "uptime_ns": int64(3 * time.Minute), }, time.Date(2018, 6, 14, 5, 51, 53, 266176036, time.UTC), ), @@ -789,13 +790,14 @@ func TestContainerStatus(t *testing.T) { "source": "e2173b9478a6", }, map[string]interface{}{ - "oomkilled": false, - "pid": 1234, - "exitcode": 0, - "container_id": "e2173b9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296b7dfb", - "started_at": time.Date(2018, 6, 14, 5, 48, 53, 266176036, time.UTC).UnixNano(), - "finished_at": time.Date(2018, 6, 14, 5, 53, 53, 266176036, time.UTC).UnixNano(), - "uptime_ns": int64(5 * time.Minute), + "oomkilled": false, + "pid": 1234, + "exitcode": 0, + "restart_count": 0, + "container_id": "e2173b9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296b7dfb", + "started_at": time.Date(2018, 6, 14, 5, 48, 53, 266176036, time.UTC).UnixNano(), + "finished_at": time.Date(2018, 6, 14, 5, 53, 53, 266176036, time.UTC).UnixNano(), + "uptime_ns": int64(5 * time.Minute), }, time.Date(2018, 6, 14, 5, 51, 53, 266176036, time.UTC), ), @@ -827,11 +829,12 @@ func TestContainerStatus(t *testing.T) { "source": "e2173b9478a6", }, map[string]interface{}{ - "oomkilled": false, - "pid": 1234, - "exitcode": 0, - "container_id": "e2173b9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296b7dfb", - "finished_at": time.Date(2018, 6, 14, 5, 53, 53, 266176036, time.UTC).UnixNano(), + "oomkilled": false, + "pid": 1234, + "exitcode": 0, + "restart_count": 0, + "container_id": "e2173b9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296b7dfb", + "finished_at": time.Date(2018, 6, 14, 5, 53, 53, 266176036, time.UTC).UnixNano(), }, time.Date(2018, 6, 14, 5, 51, 53, 266176036, time.UTC), ), @@ -863,13 +866,14 @@ func TestContainerStatus(t *testing.T) { "source": "e2173b9478a6", }, map[string]interface{}{ - "oomkilled": false, - "pid": 1234, - "exitcode": 0, - "container_id": "e2173b9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296b7dfb", - "started_at": time.Date(2019, 1, 1, 0, 0, 2, 0, time.UTC).UnixNano(), - "finished_at": time.Date(2019, 1, 1, 0, 0, 1, 0, time.UTC).UnixNano(), - "uptime_ns": int64(1 * time.Second), + "oomkilled": false, + "pid": 1234, + "exitcode": 0, + "restart_count": 0, + "container_id": "e2173b9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296b7dfb", + "started_at": time.Date(2019, 1, 1, 0, 0, 2, 0, time.UTC).UnixNano(), + "finished_at": time.Date(2019, 1, 1, 0, 0, 1, 0, time.UTC).UnixNano(), + "uptime_ns": int64(1 * time.Second), }, time.Date(2019, 1, 1, 0, 0, 3, 0, time.UTC), ),