-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Metricbeat : new metricset image for docker module #3467
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b91cb0a
Create image metricset
douaejeouit 174aa0d
add image.asciidoc
douaejeouit a0d9ee1
update CHANGELOG.asciidoc
douaejeouit 7b51927
Update image integration test
douaejeouit f85fa23
update test_docker.py
douaejeouit 261a0b0
Update data: mesure & display the creation time of the image
douaejeouit 3871ac8
complete the metricset documentation : update fields.yml
douaejeouit 42f58cd
update templates
douaejeouit 08cc803
update test_docker.py
douaejeouit f78fc9e
replace ID by identifier in feilds.yml
douaejeouit 1ef8765
test labels fields
douaejeouit ff9ab7a
replace ID by identifier
douaejeouit 443e86c
Delete the "tags" key from test_docker.py because it is not documen…
douaejeouit db79c10
Remove both tags and labels from test image fields
douaejeouit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//// | ||
This file is generated! See scripts/docs_collector.py | ||
//// | ||
|
||
[[metricbeat-metricset-docker-image]] | ||
include::../../../module/docker/image/_meta/docs.asciidoc[] | ||
|
||
|
||
==== Fields | ||
|
||
For a description of each field in the metricset, see the | ||
<<exported-fields-docker,exported fields>> section. | ||
|
||
Here is an example document generated by this metricset: | ||
|
||
[source,json] | ||
---- | ||
include::../../../module/docker/image/_meta/data.json[] | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"@timestamp":"2016-05-23T08:05:34.853Z", | ||
"beat":{ | ||
"hostname":"beathost", | ||
"name":"beathost" | ||
}, | ||
"metricset":{ | ||
"host":"localhost", | ||
"module":"docker", | ||
"name":"image", | ||
"rtt":44269 | ||
}, | ||
"docker":{ | ||
"image":{ | ||
"example": "image" | ||
} | ||
}, | ||
"type":"metricsets" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
=== docker image MetricSet | ||
|
||
This is the image metricset of the module docker. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
- name: image | ||
type: group | ||
description: > | ||
Docker image metrics. | ||
fields: | ||
- name: id | ||
type: group | ||
description: > | ||
The image layers identifier. | ||
fields: | ||
- name: current | ||
type: keyword | ||
description: > | ||
Unique image identifier given upon its creation. | ||
- name: parent | ||
type: keyword | ||
description: > | ||
Identifier of the image, if it exists, from which the current image directly descends. | ||
- name: created | ||
type: date | ||
description: > | ||
Date and time when the image was created. | ||
- name: size | ||
type: group | ||
description: > | ||
Image size layers. | ||
fields: | ||
- name: virtual | ||
type: long | ||
description: > | ||
Size of the image. | ||
- name: regular | ||
type: long | ||
description: > | ||
Total size of the all cached images associated to the current image. | ||
|
||
# TODO : How to describe tags & labels list ? | ||
# - name: tags | ||
# type: list ? | ||
# description: > | ||
# Descriptive or given name(s) to the image. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package image | ||
|
||
import ( | ||
"github.com/elastic/beats/libbeat/common" | ||
|
||
"github.com/elastic/beats/metricbeat/module/docker" | ||
dc "github.com/fsouza/go-dockerclient" | ||
"time" | ||
) | ||
|
||
func eventsMapping(imagesList []dc.APIImages) []common.MapStr { | ||
events := []common.MapStr{} | ||
for _, image := range imagesList { | ||
events = append(events, eventMapping(&image)) | ||
} | ||
return events | ||
} | ||
|
||
func eventMapping(image *dc.APIImages) common.MapStr { | ||
event := common.MapStr{ | ||
"id": common.MapStr{ | ||
"current": image.ID, | ||
"parent": image.ParentID, | ||
}, | ||
"created": common.Time(time.Unix(image.Created, 0)), | ||
"size": common.MapStr{ | ||
"regular": image.Size, | ||
"virtual": image.VirtualSize, | ||
}, | ||
"tags": image.RepoTags, | ||
} | ||
labels := docker.DeDotLabels(image.Labels) | ||
if len(labels) > 0 { | ||
event["labels"] = labels | ||
} | ||
return event | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package image | ||
|
||
import ( | ||
"github.com/elastic/beats/libbeat/common" | ||
"github.com/elastic/beats/libbeat/logp" | ||
"github.com/elastic/beats/metricbeat/mb" | ||
"github.com/elastic/beats/metricbeat/module/docker" | ||
|
||
dc "github.com/fsouza/go-dockerclient" | ||
) | ||
|
||
// init registers the MetricSet with the central registry. | ||
// The New method will be called after the setup of the module and before starting to fetch data | ||
func init() { | ||
if err := mb.Registry.AddMetricSet("docker", "image", New); err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
// MetricSet type defines all fields of the MetricSet | ||
// As a minimum it must inherit the mb.BaseMetricSet fields, but can be extended with | ||
// additional entries. These variables can be used to persist data or configuration between | ||
// multiple fetch calls. | ||
type MetricSet struct { | ||
mb.BaseMetricSet | ||
dockerClient *dc.Client | ||
} | ||
|
||
// New create a new instance of the MetricSet | ||
// Part of new is also setting up the configuration by processing additional | ||
// configuration entries if needed. | ||
func New(base mb.BaseMetricSet) (mb.MetricSet, error) { | ||
|
||
logp.Warn("EXPERIMENTAL: The docker info metricset is experimental") | ||
|
||
config := docker.Config{} | ||
if err := base.Module().UnpackConfig(&config); err != nil { | ||
return nil, err | ||
} | ||
|
||
client, err := docker.NewDockerClient(base.HostData().URI, config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &MetricSet{ | ||
BaseMetricSet: base, | ||
dockerClient: client, | ||
}, nil | ||
} | ||
|
||
// Fetch methods implements the data gathering and data conversion to the right format | ||
// It returns the event which is then forward to the output. In case of an error, a | ||
// descriptive error must be returned. | ||
func (m *MetricSet) Fetch() ([]common.MapStr, error) { | ||
|
||
images, err := m.dockerClient.ListImages(dc.ListImagesOptions{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return eventsMapping(images), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package image | ||
|
||
import ( | ||
"testing" | ||
|
||
mbtest "github.com/elastic/beats/metricbeat/mb/testing" | ||
) | ||
|
||
func TestData(t *testing.T) { | ||
f := mbtest.NewEventsFetcher(t, getConfig()) | ||
err := mbtest.WriteEvents(f, t) | ||
if err != nil { | ||
t.Fatal("write", err) | ||
} | ||
} | ||
|
||
func getConfig() map[string]interface{} { | ||
return map[string]interface{}{ | ||
"module": "docker", | ||
"metricsets": []string{"image"}, | ||
"hosts": []string{"unix:///var/run/docker.sock"}, | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs update but I can do that after merging.