Skip to content

Commit

Permalink
introduce constand MODULE_DATA
Browse files Browse the repository at this point in the history
  • Loading branch information
ruflin committed Oct 5, 2016
1 parent 8c06ee8 commit a5f1d73
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 13 deletions.
11 changes: 6 additions & 5 deletions metricbeat/beater/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/libbeat/processors"
"github.com/elastic/beats/metricbeat/mb"
)

const (
Expand Down Expand Up @@ -48,11 +49,11 @@ func (b EventBuilder) Build() (common.MapStr, error) {
}
}

// Checks if additional meta information is provided by the MetricSet under the key _module
// This is based on the convention that each MetricSet can provide module data under the key _module
moduleData, moudleDataExists := event["_module"]
// Checks if additional meta information is provided by the MetricSet under the key MODULE_DATA
// This is based on the convention that each MetricSet can provide module data under the key MODULE_DATA
moduleData, moudleDataExists := event[mb.MODULE_DATA]
if moudleDataExists {
delete(event, "_module")
delete(event, mb.MODULE_DATA)
}

event = common.MapStr{
Expand All @@ -71,7 +72,7 @@ func (b EventBuilder) Build() (common.MapStr, error) {

// In case meta data exists, it is added on the module level
if moudleDataExists {
if _, ok := event[b.ModuleName].(common.MapStr); ok {
if _, ok := moduleData.(common.MapStr); ok {
event[b.ModuleName].(common.MapStr).Update(moduleData.(common.MapStr))
}
}
Expand Down
4 changes: 4 additions & 0 deletions metricbeat/mb/mb.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (
"github.com/elastic/beats/libbeat/processors"
)

const (
MODULE_DATA string = "_module"
)

// Module interfaces

// Module is the common interface for all Module implementations.
Expand Down
7 changes: 5 additions & 2 deletions metricbeat/module/docker/cpu/data.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package cpu

import "github.com/elastic/beats/libbeat/common"
import (
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/metricbeat/mb"
)

func eventsMapping(cpuStatsList []CPUStats) []common.MapStr {
events := []common.MapStr{}
Expand All @@ -13,7 +16,7 @@ func eventsMapping(cpuStatsList []CPUStats) []common.MapStr {
func eventMapping(stats *CPUStats) common.MapStr {

event := common.MapStr{
"_module": common.MapStr{
mb.MODULE_DATA: common.MapStr{
"container": stats.Container.ToMapStr(),
},
"usage": common.MapStr{
Expand Down
7 changes: 5 additions & 2 deletions metricbeat/module/docker/diskio/data.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package diskio

import "github.com/elastic/beats/libbeat/common"
import (
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/metricbeat/mb"
)

func eventsMapping(blkioStatsList []BlkioStats) []common.MapStr {
myEvents := []common.MapStr{}
Expand All @@ -12,7 +15,7 @@ func eventsMapping(blkioStatsList []BlkioStats) []common.MapStr {

func eventMapping(stats *BlkioStats) common.MapStr {
event := common.MapStr{
"_module": common.MapStr{
mb.MODULE_DATA: common.MapStr{
"container": stats.Container.ToMapStr(),
},
"reads": stats.reads,
Expand Down
7 changes: 5 additions & 2 deletions metricbeat/module/docker/memory/data.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package memory

import "github.com/elastic/beats/libbeat/common"
import (
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/metricbeat/mb"
)

func eventsMapping(memoryDataList []MemoryData) []common.MapStr {
events := []common.MapStr{}
Expand All @@ -13,7 +16,7 @@ func eventsMapping(memoryDataList []MemoryData) []common.MapStr {
func eventMapping(memoryData *MemoryData) common.MapStr {

event := common.MapStr{
"_module": common.MapStr{
mb.MODULE_DATA: common.MapStr{
"container": memoryData.Container.ToMapStr(),
},
"fail": common.MapStr{
Expand Down
7 changes: 5 additions & 2 deletions metricbeat/module/docker/network/data.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package network

import "github.com/elastic/beats/libbeat/common"
import (
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/metricbeat/mb"
)

func eventsMapping(netsStatsList []NETstats) []common.MapStr {
myEvents := []common.MapStr{}
Expand All @@ -12,7 +15,7 @@ func eventsMapping(netsStatsList []NETstats) []common.MapStr {

func eventMapping(stats *NETstats) common.MapStr {
event := common.MapStr{
"_module": common.MapStr{
mb.MODULE_DATA: common.MapStr{
"container": stats.Container.ToMapStr(),
},
"interface": stats.NameInterface,
Expand Down

0 comments on commit a5f1d73

Please sign in to comment.