-
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
Add HealthCheck information for Metricbeat docker module #3357
Changes from 12 commits
48c52a9
cef2bc8
0168682
8f0ed13
bebac8f
1009222
b95e76a
cd0cebc
3d743aa
2e29629
6ff4edf
2e9ab40
d8e7256
2e8d78e
3e83526
619b19f
76bb65a
b604279
4a8e710
daeba37
61273fc
3391a69
09aa8c8
b14b290
fc031d8
8a2e17b
0be7340
ffceff3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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-healthcheck]] | ||
include::../../../module/docker/healthcheck/_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/healthcheck/_meta/data.json[] | ||
---- |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,4 +32,4 @@ | |
"rtt": 115 | ||
}, | ||
"type": "metricsets" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,12 @@ | ||
package: github.com/elastic/beats/metricbeat/module/docker | ||
import: | ||
- package: github.com/fsouza/go-dockerclient | ||
version: 23c589186c2a92a8742da55f19aec4997dae5cbb | ||
version: e085edda407c05214cc6e71e4881de47667e77ec | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No changes should be needed here anymore. |
||
- package: github.com/docker/docker | ||
version: 8bc7e193464b5b59a2019a4a429a48526f71bc40 | ||
- package: github.com/docker/go-units | ||
version: e30f1e79f3cd72542f2026ceec18d3bd67ab859c | ||
- package: github.com/hashicorp/go-cleanhttp | ||
version: ad28ea4487f05916463e2423a55166280e8254b5 | ||
- package: github.com/Microsoft/go-winio | ||
version: v0.3.7 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"@timestamp": "2016-05-23T08:05:34.853Z", | ||
"beat": { | ||
"hostname": "host.example.com", | ||
"name": "host.example.com" | ||
}, | ||
"docker": { | ||
"healthcheck": { | ||
"event_end_date": "2017-01-09T20:38:13.080472813+01:00", | ||
"event_exit_code": 0, | ||
"event_output": "this is an event output", | ||
"event_start_date": "2017-01-09T20:38:12.999970865+01:00", | ||
"failingstreak": 0, | ||
"status": "healthy" | ||
} | ||
}, | ||
"metricset": { | ||
"host": "/var/run/docker.sock", | ||
"module": "docker", | ||
"name": "container", | ||
"rtt": 115 | ||
}, | ||
"type": "metricsets" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
=== Docker healthcheck Metricset | ||
|
||
The Docker `healthcheck` metricset collects information and statistics about | ||
running Docker containers. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
- name: healthcheck | ||
type: group | ||
description: > | ||
Docker container metrics. | ||
fields: | ||
- name: event_end_date | ||
type: date | ||
description: > | ||
Healthcheck end date | ||
- name: event_start_date | ||
type: date | ||
description: > | ||
Healthcheck start date | ||
- name: event_output | ||
type: keyword | ||
description: > | ||
Healthcheck output | ||
- name: event_exit_code | ||
type: integer | ||
description: > | ||
Healthcheck status code | ||
- name: failingstreak | ||
type: integer | ||
description: > | ||
concurent failed check | ||
- name: status | ||
type: keyword | ||
description: > | ||
Healthcheck status code |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// +build integration | ||
|
||
package healthcheck | ||
|
||
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{"healthcheck"}, | ||
"hosts": []string{"unix:///var/run/docker.sock"}, | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package healthcheck | ||
|
||
import ( | ||
//"time" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line can be removed. |
||
|
||
"github.com/elastic/beats/libbeat/common" | ||
"github.com/elastic/beats/metricbeat/mb" | ||
"github.com/elastic/beats/metricbeat/module/docker" | ||
|
||
dc "github.com/fsouza/go-dockerclient" | ||
"reflect" | ||
"strings" | ||
) | ||
|
||
func eventsMapping(containersList []dc.APIContainers, m *MetricSet) []common.MapStr { | ||
myEvents := []common.MapStr{} | ||
// Set an empty map in order to detect empty healthcheck event | ||
emptyEvent := common.MapStr{} | ||
for _, container := range containersList { | ||
returnevent := eventMapping(&container, m) | ||
// Compare event to empty event | ||
if !reflect.DeepEqual(emptyEvent, returnevent) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. eventMapping should just return nil if there is no event. |
||
myEvents = append(myEvents, eventMapping(&container, m)) | ||
} | ||
} | ||
return myEvents | ||
} | ||
|
||
func eventMapping(cont *dc.APIContainers, m *MetricSet) common.MapStr { | ||
event := common.MapStr{} | ||
// Detect if healthcheck is available for container | ||
if strings.Contains(cont.Status, "(") && strings.Contains(cont.Status, ")") { | ||
container, _ := m.dockerClient.InspectContainer(cont.ID) | ||
last_event := len(container.State.Health.Log) - 1 | ||
// Detect if an healthcheck already occured | ||
if last_event >= 0 { | ||
event = common.MapStr{ | ||
mb.ModuleData: common.MapStr{ | ||
"container": common.MapStr{ | ||
"name": docker.ExtractContainerName(cont.Names), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a possibility that we use the same semantics as we have in other docker metricsets to add the full container info? |
||
}, | ||
}, | ||
"status": container.State.Health.Status, | ||
"failingstreak": container.State.Health.FailingStreak, | ||
"event_start_date": common.Time(container.State.Health.Log[last_event].Start), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should map all event data under |
||
"event_end_date": common.Time(container.State.Health.Log[last_event].End), | ||
"event_exit_code": container.State.Health.Log[last_event].ExitCode, | ||
"event_output": container.State.Health.Log[last_event].Output, | ||
} | ||
} | ||
} | ||
|
||
return event | ||
} |
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.
We should sort this alphabetically (not introduce by you).