Strip container_version from container_image tag

closes #1413
This commit is contained in:
Cameron Sparr 2016-07-19 17:31:01 +01:00
parent 42d9d5d237
commit 191608041f
3 changed files with 20 additions and 7 deletions

View File

@ -2,6 +2,8 @@
### Features ### Features
- [#1413](https://github.com/influxdata/telegraf/issues/1413): Separate container_version from container_image tag.
### Bugfixes ### Bugfixes
- [#1519](https://github.com/influxdata/telegraf/pull/1519): Fix error race conditions and partial failures. - [#1519](https://github.com/influxdata/telegraf/pull/1519): Fix error race conditions and partial failures.

View File

@ -207,9 +207,18 @@ func (d *Docker) gatherContainer(
cname = strings.TrimPrefix(container.Names[0], "/") cname = strings.TrimPrefix(container.Names[0], "/")
} }
// the image name sometimes has a version part.
// ie, rabbitmq:3-management
imageParts := strings.Split(container.Image, ":")
imageName := imageParts[0]
imageVersion := "unknown"
if len(imageParts) > 1 {
imageVersion = imageParts[1]
}
tags := map[string]string{ tags := map[string]string{
"container_name": cname, "container_name": cname,
"container_image": container.Image, "container_image": imageName,
"container_version": imageVersion,
} }
if len(d.ContainerNames) > 0 { if len(d.ContainerNames) > 0 {
if !sliceContains(cname, d.ContainerNames) { if !sliceContains(cname, d.ContainerNames) {

View File

@ -378,9 +378,10 @@ func TestDockerGatherInfo(t *testing.T) {
"container_id": "b7dfbb9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296e2173", "container_id": "b7dfbb9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296e2173",
}, },
map[string]string{ map[string]string{
"container_name": "etcd2", "container_name": "etcd2",
"container_image": "quay.io/coreos/etcd:v2.2.2", "container_image": "quay.io/coreos/etcd",
"cpu": "cpu3", "cpu": "cpu3",
"container_version": "v2.2.2",
}, },
) )
acc.AssertContainsTaggedFields(t, acc.AssertContainsTaggedFields(t,
@ -423,8 +424,9 @@ func TestDockerGatherInfo(t *testing.T) {
"container_id": "b7dfbb9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296e2173", "container_id": "b7dfbb9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296e2173",
}, },
map[string]string{ map[string]string{
"container_name": "etcd2", "container_name": "etcd2",
"container_image": "quay.io/coreos/etcd:v2.2.2", "container_image": "quay.io/coreos/etcd",
"container_version": "v2.2.2",
}, },
) )