docker: add container_id to blkio metrics

all container metrics except blkio have this field
This commit is contained in:
Jörg Thalheim 2016-05-04 12:17:23 +00:00
parent 0b9b7bddd7
commit 7c5e8776f3
3 changed files with 5 additions and 1 deletions

View File

@ -98,6 +98,7 @@ based on the availability of per-cpu stats on your system.
- io_serviced_recursive_sync - io_serviced_recursive_sync
- io_serviced_recursive_total - io_serviced_recursive_total
- io_serviced_recursive_write - io_serviced_recursive_write
- container_id
- docker_ - docker_
- n_used_file_descriptors - n_used_file_descriptors
- n_cpus - n_cpus

View File

@ -328,7 +328,7 @@ func gatherContainerStats(
acc.AddFields("docker_container_net", netfields, nettags, now) acc.AddFields("docker_container_net", netfields, nettags, now)
} }
gatherBlockIOMetrics(stat, acc, tags, now) gatherBlockIOMetrics(stat, acc, tags, now, id)
} }
func calculateMemPercent(stat *types.StatsJSON) float64 { func calculateMemPercent(stat *types.StatsJSON) float64 {
@ -356,6 +356,7 @@ func gatherBlockIOMetrics(
acc telegraf.Accumulator, acc telegraf.Accumulator,
tags map[string]string, tags map[string]string,
now time.Time, now time.Time,
id string,
) { ) {
blkioStats := stat.BlkioStats blkioStats := stat.BlkioStats
// Make a map of devices to their block io stats // Make a map of devices to their block io stats
@ -420,6 +421,7 @@ func gatherBlockIOMetrics(
for device, fields := range deviceStatMap { for device, fields := range deviceStatMap {
iotags := copyTags(tags) iotags := copyTags(tags)
iotags["device"] = device iotags["device"] = device
fields["container_id"] = id
acc.AddFields("docker_container_blkio", fields, iotags, now) acc.AddFields("docker_container_blkio", fields, iotags, now)
} }
} }

View File

@ -48,6 +48,7 @@ func TestDockerGatherContainerStats(t *testing.T) {
blkiofields := map[string]interface{}{ blkiofields := map[string]interface{}{
"io_service_bytes_recursive_read": uint64(100), "io_service_bytes_recursive_read": uint64(100),
"io_serviced_recursive_write": uint64(101), "io_serviced_recursive_write": uint64(101),
"container_id": "123456789",
} }
acc.AssertContainsTaggedFields(t, "docker_container_blkio", blkiofields, blkiotags) acc.AssertContainsTaggedFields(t, "docker_container_blkio", blkiofields, blkiotags)