Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ip address of containers to event #5379

Merged
merged 1 commit into from
Oct 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}