fix(inputs.docker): Add restart count (#13646)

This commit is contained in:
Joshua Powers 2023-07-24 01:25:31 -06:00 committed by GitHub
parent cb354a9d9a
commit 54b1009a9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 29 deletions

View File

@ -515,10 +515,11 @@ func (d *Docker) gatherContainerInspect(
if info.State != nil { if info.State != nil {
tags["container_status"] = info.State.Status tags["container_status"] = info.State.Status
statefields := map[string]interface{}{ statefields := map[string]interface{}{
"oomkilled": info.State.OOMKilled, "oomkilled": info.State.OOMKilled,
"pid": info.State.Pid, "pid": info.State.Pid,
"exitcode": info.State.ExitCode, "exitcode": info.State.ExitCode,
"container_id": container.ID, "restart_count": info.RestartCount,
"container_id": container.ID,
} }
finished, err := time.Parse(time.RFC3339, info.State.FinishedAt) finished, err := time.Parse(time.RFC3339, info.State.FinishedAt)

View File

@ -753,12 +753,13 @@ func TestContainerStatus(t *testing.T) {
"source": "e2173b9478a6", "source": "e2173b9478a6",
}, },
map[string]interface{}{ map[string]interface{}{
"oomkilled": false, "oomkilled": false,
"pid": 1234, "pid": 1234,
"exitcode": 0, "restart_count": 0,
"container_id": "e2173b9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296b7dfb", "exitcode": 0,
"started_at": time.Date(2018, 6, 14, 5, 48, 53, 266176036, time.UTC).UnixNano(), "container_id": "e2173b9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296b7dfb",
"uptime_ns": int64(3 * time.Minute), "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), time.Date(2018, 6, 14, 5, 51, 53, 266176036, time.UTC),
), ),
@ -789,13 +790,14 @@ func TestContainerStatus(t *testing.T) {
"source": "e2173b9478a6", "source": "e2173b9478a6",
}, },
map[string]interface{}{ map[string]interface{}{
"oomkilled": false, "oomkilled": false,
"pid": 1234, "pid": 1234,
"exitcode": 0, "exitcode": 0,
"container_id": "e2173b9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296b7dfb", "restart_count": 0,
"started_at": time.Date(2018, 6, 14, 5, 48, 53, 266176036, time.UTC).UnixNano(), "container_id": "e2173b9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296b7dfb",
"finished_at": time.Date(2018, 6, 14, 5, 53, 53, 266176036, time.UTC).UnixNano(), "started_at": time.Date(2018, 6, 14, 5, 48, 53, 266176036, time.UTC).UnixNano(),
"uptime_ns": int64(5 * time.Minute), "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), time.Date(2018, 6, 14, 5, 51, 53, 266176036, time.UTC),
), ),
@ -827,11 +829,12 @@ func TestContainerStatus(t *testing.T) {
"source": "e2173b9478a6", "source": "e2173b9478a6",
}, },
map[string]interface{}{ map[string]interface{}{
"oomkilled": false, "oomkilled": false,
"pid": 1234, "pid": 1234,
"exitcode": 0, "exitcode": 0,
"container_id": "e2173b9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296b7dfb", "restart_count": 0,
"finished_at": time.Date(2018, 6, 14, 5, 53, 53, 266176036, time.UTC).UnixNano(), "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), time.Date(2018, 6, 14, 5, 51, 53, 266176036, time.UTC),
), ),
@ -863,13 +866,14 @@ func TestContainerStatus(t *testing.T) {
"source": "e2173b9478a6", "source": "e2173b9478a6",
}, },
map[string]interface{}{ map[string]interface{}{
"oomkilled": false, "oomkilled": false,
"pid": 1234, "pid": 1234,
"exitcode": 0, "exitcode": 0,
"container_id": "e2173b9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296b7dfb", "restart_count": 0,
"started_at": time.Date(2019, 1, 1, 0, 0, 2, 0, time.UTC).UnixNano(), "container_id": "e2173b9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296b7dfb",
"finished_at": time.Date(2019, 1, 1, 0, 0, 1, 0, time.UTC).UnixNano(), "started_at": time.Date(2019, 1, 1, 0, 0, 2, 0, time.UTC).UnixNano(),
"uptime_ns": int64(1 * time.Second), "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), time.Date(2019, 1, 1, 0, 0, 3, 0, time.UTC),
), ),