Skip to content

Commit

Permalink
Add ip address of containers to event
Browse files Browse the repository at this point in the history
  • Loading branch information
liketic committed Oct 25, 2017
1 parent d1dfc7e commit ebf27ef
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ https://github.com/elastic/beats/compare/v6.0.0-beta2...master[Check the HEAD di
- Auto-select a hostname (based on the host on which the Beat is running) in the Host Overview dashboard. {pull}5340[5340]
- Add Kubernetes manifests to deploy Metricbeat. {pull}5349[5349]
- Add etcd module. {issue}4970[4970]
- Add ip address of docker containers to event. {pull}5379[5379]

*Packetbeat*

Expand Down
8 changes: 8 additions & 0 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -1908,6 +1908,14 @@ type: keyword
Container status.
[float]
=== `docker.container.ip_addresses`
type: keyword
Container IP addresses.
[float]
== size fields
Expand Down
3 changes: 3 additions & 0 deletions metricbeat/module/docker/container/_meta/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
"com_docker_compose_version": "1.9.0-rc4"
},
"name": "environments_beat_run_1",
"ip_addresses": [
"10.0.0.1"
],
"size": {
"root_fs": 0,
"rw": 0
Expand Down
4 changes: 4 additions & 0 deletions metricbeat/module/docker/container/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
type: keyword
description: >
Container status.
- name: ip_addresses
type: keyword
description: >
Container IP addresses.
- name: size
type: group
description: >
Expand Down
19 changes: 14 additions & 5 deletions metricbeat/module/docker/container/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ func eventsMapping(containersList []dc.APIContainers) []common.MapStr {

func eventMapping(cont *dc.APIContainers) common.MapStr {
event := common.MapStr{
"created": common.Time(time.Unix(cont.Created, 0)),
"id": cont.ID,
"name": docker.ExtractContainerName(cont.Names),
"command": cont.Command,
"image": cont.Image,
"created": common.Time(time.Unix(cont.Created, 0)),
"id": cont.ID,
"name": docker.ExtractContainerName(cont.Names),
"command": cont.Command,
"image": cont.Image,
"ip_addresses": extractIPAddresses(cont.Networks),
"size": common.MapStr{
"root_fs": cont.SizeRootFs,
"rw": cont.SizeRw,
Expand All @@ -39,3 +40,11 @@ func eventMapping(cont *dc.APIContainers) common.MapStr {

return event
}

func extractIPAddresses(networks dc.NetworkList) []string {
ipAddresses := make([]string, 0, len(networks.Networks))
for _, network := range networks.Networks {
ipAddresses = append(ipAddresses, network.IPAddress)
}
return ipAddresses
}

0 comments on commit ebf27ef

Please sign in to comment.