Skip to content

Commit

Permalink
Add container status tag to docker input (influxdata#4259)
Browse files Browse the repository at this point in the history
  • Loading branch information
prashanthjbabu authored and otherpirate committed Mar 15, 2019
1 parent 6b308a4 commit fd1bd32
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
17 changes: 17 additions & 0 deletions plugins/inputs/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,23 @@ func (d *Docker) gatherContainer(
}
}
}
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_time, err := time.Parse(time.RFC3339, info.State.StartedAt)
if err == nil && !container_time.IsZero() {
statefields["started_at"] = container_time.UnixNano()
}
container_time, err = time.Parse(time.RFC3339, info.State.FinishedAt)
if err == nil && !container_time.IsZero() {
statefields["finished_at"] = container_time.UnixNano()
}
acc.AddFields("docker_container_status", statefields, tags, time.Now())
}

if info.State.Health != nil {
healthfields := map[string]interface{}{
Expand Down
2 changes: 2 additions & 0 deletions plugins/inputs/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ func TestDockerGatherInfo(t *testing.T) {
"label1": "test_value_1",
"label2": "test_value_2",
"server_version": "17.09.0-ce",
"container_status": "running",
},
)
acc.AssertContainsTaggedFields(t,
Expand All @@ -676,6 +677,7 @@ func TestDockerGatherInfo(t *testing.T) {
"label1": "test_value_1",
"label2": "test_value_2",
"server_version": "17.09.0-ce",
"container_status": "running",
},
)
}
Expand Down
6 changes: 6 additions & 0 deletions plugins/inputs/docker/docker_testdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,12 @@ var containerInspect = types.ContainerJSON{
FailingStreak: 1,
Status: "Unhealthy",
},
Status: "running",
OOMKilled: false,
Pid: 1234,
ExitCode: 0,
StartedAt: "2018-06-14T05:48:53.266176036Z",
FinishedAt: "0001-01-01T00:00:00Z",
},
},
}

0 comments on commit fd1bd32

Please sign in to comment.