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 HealthCheck information for Metricbeat docker module #3357

Merged
merged 28 commits into from
Jan 25, 2017
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
48c52a9
Add health to standalone container
Jan 10, 2017
cef2bc8
Add node metricset
Jan 10, 2017
0168682
Add node module for docker metricset
Jan 10, 2017
8f0ed13
Fix docker dependency issue
Jan 10, 2017
bebac8f
Add docker service metricset
Jan 11, 2017
1009222
Fix service index mapping and add comment
Jan 11, 2017
b95e76a
add healthcheck metricset in docker module
Jan 20, 2017
cd0cebc
add healthcheck metricset in docker module
Jan 20, 2017
3d743aa
delete old fsouza lib (node.go and service.go)
Jan 20, 2017
2e29629
Set metricbeat.full.yml to default value
Jan 20, 2017
6ff4edf
Fix shell in metricbeat.full.yml
Jan 20, 2017
2e9ab40
Last commit, add comment
Jan 20, 2017
d8e7256
set metricset list in alphabetical order, remap event healtcheck data…
Jan 20, 2017
2e8d78e
Add health to standalone container
Jan 10, 2017
3e83526
Rebase on top of elastic/beats:master
Jan 20, 2017
619b19f
Add node module for docker metricset
Jan 10, 2017
76bb65a
Fix docker dependency issue
Jan 10, 2017
b604279
Add docker service metricset
Jan 11, 2017
4a8e710
Fix service index mapping and add comment
Jan 11, 2017
daeba37
add healthcheck metricset in docker module
Jan 20, 2017
61273fc
add healthcheck metricset in docker module
Jan 20, 2017
3391a69
Set metricbeat.full.yml to default value
Jan 20, 2017
09aa8c8
Fix shell in metricbeat.full.yml
Jan 20, 2017
b14b290
Last commit, add comment
Jan 20, 2017
fc031d8
set metricset list in alphabetical order, remap event healtcheck data…
Jan 20, 2017
8a2e17b
Merge branch 'master' of https://github.com/Treeptik/beats
Jan 20, 2017
0be7340
Delete external libs folder
Jan 20, 2017
ffceff3
fix healtheck layer, add node.go and service.go, compare event to nil
Jan 23, 2017
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
2 changes: 1 addition & 1 deletion metricbeat/_meta/beat.full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ metricbeat.modules:

#------------------------------- Docker Module -------------------------------
#- module: docker
#metricsets: ["cpu", "info", "memory", "network", "diskio", "container"]
#metricsets: ["container", "cpu", "diskio", "healthcheck", "info", "memory", "network"]
#hosts: ["unix:///var/run/docker.sock"]
#enabled: true
#period: 10s
Expand Down
62 changes: 62 additions & 0 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,68 @@ type: scaled_float
Number of reads and writes combined.


[float]
== healthcheck Fields

Docker container metrics.



[float]
=== docker.healthcheck.failingstreak

type: integer

concurent failed check


[float]
=== docker.healthcheck.status

type: keyword

Healthcheck status code


[float]
== event Fields

event fields.



[float]
=== docker.healthcheck.event.end_date

type: date

Healthcheck end date


[float]
=== docker.healthcheck.event.start_date

type: date

Healthcheck start date


[float]
=== docker.healthcheck.event.output

type: keyword

Healthcheck output


[float]
=== docker.healthcheck.event.exit_code

type: integer

Healthcheck status code


[float]
== info Fields

Expand Down
6 changes: 5 additions & 1 deletion metricbeat/docs/modules/docker.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ in <<configuration-metricbeat>>. Here is an example configuration:
----
metricbeat.modules:
#- module: docker
#metricsets: ["cpu", "info", "memory", "network", "diskio", "container"]
#metricsets: ["container", "cpu", "diskio", "healthcheck", "info", "memory", "network"]
#hosts: ["unix:///var/run/docker.sock"]
#enabled: true
#period: 10s
Expand All @@ -44,6 +44,8 @@ The following metricsets are available:

* <<metricbeat-metricset-docker-diskio,diskio>>

* <<metricbeat-metricset-docker-healthcheck,healthcheck>>

* <<metricbeat-metricset-docker-info,info>>

* <<metricbeat-metricset-docker-memory,memory>>
Expand All @@ -56,6 +58,8 @@ include::docker/cpu.asciidoc[]

include::docker/diskio.asciidoc[]

include::docker/healthcheck.asciidoc[]

include::docker/info.asciidoc[]

include::docker/memory.asciidoc[]
Expand Down
19 changes: 19 additions & 0 deletions metricbeat/docs/modules/docker/healthcheck.asciidoc
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[]
----
1 change: 1 addition & 0 deletions metricbeat/include/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
_ "github.com/elastic/beats/metricbeat/module/docker/container"
_ "github.com/elastic/beats/metricbeat/module/docker/cpu"
_ "github.com/elastic/beats/metricbeat/module/docker/diskio"
_ "github.com/elastic/beats/metricbeat/module/docker/healthcheck"
_ "github.com/elastic/beats/metricbeat/module/docker/info"
_ "github.com/elastic/beats/metricbeat/module/docker/memory"
_ "github.com/elastic/beats/metricbeat/module/docker/network"
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/metricbeat.full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ metricbeat.modules:

#------------------------------- Docker Module -------------------------------
#- module: docker
#metricsets: ["cpu", "info", "memory", "network", "diskio", "container"]
#metricsets: ["container", "cpu", "diskio", "healthcheck", "info", "memory", "network"]
#hosts: ["unix:///var/run/docker.sock"]
#enabled: true
#period: 10s
Expand Down
30 changes: 30 additions & 0 deletions metricbeat/metricbeat.template-es2x.json
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,36 @@
}
}
},
"healthcheck": {
"properties": {
"event": {
"properties": {
"end_date": {
"type": "date"
},
"exit_code": {
"type": "long"
},
"output": {
"ignore_above": 1024,
"index": "not_analyzed",
"type": "string"
},
"start_date": {
"type": "date"
}
}
},
"failingstreak": {
"type": "long"
},
"status": {
"ignore_above": 1024,
"index": "not_analyzed",
"type": "string"
}
}
},
"info": {
"properties": {
"containers": {
Expand Down
28 changes: 28 additions & 0 deletions metricbeat/metricbeat.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,34 @@
}
}
},
"healthcheck": {
"properties": {
"event": {
"properties": {
"end_date": {
"type": "date"
},
"exit_code": {
"type": "long"
},
"output": {
"ignore_above": 1024,
"type": "keyword"
},
"start_date": {
"type": "date"
}
}
},
"failingstreak": {
"type": "long"
},
"status": {
"ignore_above": 1024,
"type": "keyword"
}
}
},
"info": {
"properties": {
"containers": {
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/docker/_meta/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#- module: docker
#metricsets: ["cpu", "info", "memory", "network", "diskio", "container"]
#metricsets: ["container", "cpu", "diskio", "healthcheck", "info", "memory", "network"]
#hosts: ["unix:///var/run/docker.sock"]
#enabled: true
#period: 10s
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/docker/container/_meta/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
"rtt": 115
},
"type": "metricsets"
}
}
1 change: 1 addition & 0 deletions metricbeat/module/docker/container/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func eventMapping(cont *dc.APIContainers) common.MapStr {
}

labels := docker.DeDotLabels(cont.Labels)

if len(labels) > 0 {
event["labels"] = labels
}
Expand Down
28 changes: 28 additions & 0 deletions metricbeat/module/docker/healthcheck/_meta/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"@timestamp": "2016-05-23T08:05:34.853Z",
"beat": {
"hostname": "host.example.com",
"name": "host.example.com"
},
"docker": {
"healthcheck": {
"failingstreak": 0,
"status": "healthy",
"healthcheck": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have an additional layer here?

"event": {
"end_date": "2017-01-09T20:38:13.080472813+01:00",
"exit_code": 0,
"output": "this is an event output",
"start_date": "2017-01-09T20:38:12.999970865+01:00",
}
}
}
},
"metricset": {
"host": "/var/run/docker.sock",
"module": "docker",
"name": "container",
"rtt": 115
},
"type": "metricsets"
}
4 changes: 4 additions & 0 deletions metricbeat/module/docker/healthcheck/_meta/docs.asciidoc
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.
34 changes: 34 additions & 0 deletions metricbeat/module/docker/healthcheck/_meta/fields.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
- name: healthcheck
type: group
description: >
Docker container metrics.
fields:
- name: failingstreak
type: integer
description: >
concurent failed check
- name: status
type: keyword
description: >
Healthcheck status code
- name: event
type: group
description: >
event fields.
fields:
- name: end_date
type: date
description: >
Healthcheck end date
- name: start_date
type: date
description: >
Healthcheck start date
- name: output
type: keyword
description: >
Healthcheck output
- name: exit_code
type: integer
description: >
Healthcheck status code
25 changes: 25 additions & 0 deletions metricbeat/module/docker/healthcheck/container_integration_test.go
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"},
}
}
52 changes: 52 additions & 0 deletions metricbeat/module/docker/healthcheck/data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package healthcheck

import (
"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{}
for _, container := range containersList {
returnevent := eventMapping(&container, m)
// Compare event to empty event
if !reflect.ValueOf(returnevent).IsNil() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to just do returnevent != nil here instead of using reflect package.

myEvents = append(myEvents, returnevent)
}
}
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),
Copy link
Member

Choose a reason for hiding this comment

The 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": common.MapStr{
"start_date": common.Time(container.State.Health.Log[last_event].Start),
"end_date": common.Time(container.State.Health.Log[last_event].End),
"exit_code": container.State.Health.Log[last_event].ExitCode,
"output": container.State.Health.Log[last_event].Output,
},
}
return event
}
}
return nil
}
Loading