Skip to content

Commit

Permalink
Add container_id field to docker_container_status metrics (influxdata…
Browse files Browse the repository at this point in the history
  • Loading branch information
masuyama-ascade authored and Mathieu Lecarme committed Apr 17, 2020
1 parent feababa commit c4a8c4c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions plugins/inputs/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ status if configured.
- container_status
- container_version
- fields:
- container_id
- oomkilled (boolean)
- pid (integer)
- exitcode (integer)
Expand Down
7 changes: 4 additions & 3 deletions plugins/inputs/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,10 @@ 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,
"oomkilled": info.State.OOMKilled,
"pid": info.State.Pid,
"exitcode": info.State.ExitCode,
"container_id": container.ID,
}

finished, err := time.Parse(time.RFC3339, info.State.FinishedAt)
Expand Down
26 changes: 26 additions & 0 deletions plugins/inputs/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,32 @@ func TestDockerGatherInfo(t *testing.T) {
"container_status": "running",
},
)

acc.AssertContainsTaggedFields(t,
"docker_container_status",
map[string]interface{}{
"container_id": "b7dfbb9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296e2173",
"exitcode": int(0),
"oomkilled": false,
"pid": int(1234),
"started_at": int64(1528955333266176036),
//"finished_at": float64(0),
},
map[string]string{
"engine_host": "absol",
"container_name": "etcd2",
"container_image": "quay.io:4443/coreos/etcd",
"container_version": "v2.2.2",
"ENVVAR1": "loremipsum",
"ENVVAR2": "dolorsitamet",
"ENVVAR3": "=ubuntu:10.04",
"ENVVAR7": "ENVVAR8=ENVVAR9",
"label1": "test_value_1",
"label2": "test_value_2",
"server_version": "17.09.0-ce",
"container_status": "running",
},
)
}

func TestDockerGatherSwarmInfo(t *testing.T) {
Expand Down

0 comments on commit c4a8c4c

Please sign in to comment.