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

Move elasticsearch node_stats metricset under node.stats namespace #4142

Merged
merged 1 commit into from
May 9, 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 @@ -170,6 +170,7 @@ https://github.com/elastic/beats/compare/v5.4.0...v6.0.0-alpha1[View commits]
- Add experimental Vsphere module. {pull}4028[4028]
- Add experimental Elasticsearch module. {pull}3903[3903]
- Add experimental Kibana module. {pull}3895[3895]
- Move elasticsearch metricset node_stats under node.stats namespace. {pull}4142[4142]

*Packetbeat*

Expand Down
2 changes: 1 addition & 1 deletion libbeat/tests/system/beat/beat.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import yaml
from datetime import datetime, timedelta

BEAT_REQUIRED_FIELDS = ["@timestamp", "type",
BEAT_REQUIRED_FIELDS = ["@timestamp",
"beat.name", "beat.hostname", "beat.version"]

INTEGRATION_TESTS = os.environ.get('INTEGRATION_TESTS', False)
Expand Down
52 changes: 22 additions & 30 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -1956,20 +1956,12 @@ Node version.


[float]
== node_stats Fields
== node.stats Fields

node_stats



[float]
=== elasticsearch.node_stats.name

type: keyword

Node name.


[float]
== indices Fields

Expand All @@ -1978,31 +1970,31 @@ Node indices stats


[float]
=== elasticsearch.node_stats.indices.docs.count
=== elasticsearch.node.stats.indices.docs.count

type: long

Total number of existing documents.


[float]
=== elasticsearch.node_stats.indices.docs.deleted
=== elasticsearch.node.stats.indices.docs.deleted

type: long

Total number of deleted documents.


[float]
=== elasticsearch.node_stats.indices.segments.count
=== elasticsearch.node.stats.indices.segments.count

type: long

Total number of segments.


[float]
=== elasticsearch.node_stats.indices.segments.memory.bytes
=== elasticsearch.node.stats.indices.segments.memory.bytes

type: long

Expand All @@ -2012,7 +2004,7 @@ Total size of segments in bytes.


[float]
=== elasticsearch.node_stats.indices.store.size.bytes
=== elasticsearch.node.stats.indices.store.size.bytes

type: long

Expand All @@ -2034,7 +2026,7 @@ Old memory pool stats.


[float]
=== elasticsearch.node_stats.jvm.mem.pools.old.max.bytes
=== elasticsearch.node.stats.jvm.mem.pools.old.max.bytes

type: long

Expand All @@ -2043,7 +2035,7 @@ format: bytes
Max bytes.

[float]
=== elasticsearch.node_stats.jvm.mem.pools.old.peak.bytes
=== elasticsearch.node.stats.jvm.mem.pools.old.peak.bytes

type: long

Expand All @@ -2052,7 +2044,7 @@ format: bytes
Peak bytes.

[float]
=== elasticsearch.node_stats.jvm.mem.pools.old.peak_max.bytes
=== elasticsearch.node.stats.jvm.mem.pools.old.peak_max.bytes

type: long

Expand All @@ -2061,7 +2053,7 @@ format: bytes
Peak max bytes.

[float]
=== elasticsearch.node_stats.jvm.mem.pools.old.used.bytes
=== elasticsearch.node.stats.jvm.mem.pools.old.used.bytes

type: long

Expand All @@ -2077,7 +2069,7 @@ Young memory pool stats.


[float]
=== elasticsearch.node_stats.jvm.mem.pools.young.max.bytes
=== elasticsearch.node.stats.jvm.mem.pools.young.max.bytes

type: long

Expand All @@ -2086,7 +2078,7 @@ format: bytes
Max bytes.

[float]
=== elasticsearch.node_stats.jvm.mem.pools.young.peak.bytes
=== elasticsearch.node.stats.jvm.mem.pools.young.peak.bytes

type: long

Expand All @@ -2095,7 +2087,7 @@ format: bytes
Peak bytes.

[float]
=== elasticsearch.node_stats.jvm.mem.pools.young.peak_max.bytes
=== elasticsearch.node.stats.jvm.mem.pools.young.peak_max.bytes

type: long

Expand All @@ -2104,7 +2096,7 @@ format: bytes
Peak max bytes.

[float]
=== elasticsearch.node_stats.jvm.mem.pools.young.used.bytes
=== elasticsearch.node.stats.jvm.mem.pools.young.used.bytes

type: long

Expand All @@ -2120,7 +2112,7 @@ Survivor memory pool stats.


[float]
=== elasticsearch.node_stats.jvm.mem.pools.survivor.max.bytes
=== elasticsearch.node.stats.jvm.mem.pools.survivor.max.bytes

type: long

Expand All @@ -2129,7 +2121,7 @@ format: bytes
Max bytes.

[float]
=== elasticsearch.node_stats.jvm.mem.pools.survivor.peak.bytes
=== elasticsearch.node.stats.jvm.mem.pools.survivor.peak.bytes

type: long

Expand All @@ -2138,7 +2130,7 @@ format: bytes
Peak bytes.

[float]
=== elasticsearch.node_stats.jvm.mem.pools.survivor.peak_max.bytes
=== elasticsearch.node.stats.jvm.mem.pools.survivor.peak_max.bytes

type: long

Expand All @@ -2147,7 +2139,7 @@ format: bytes
Peak max bytes.

[float]
=== elasticsearch.node_stats.jvm.mem.pools.survivor.used.bytes
=== elasticsearch.node.stats.jvm.mem.pools.survivor.used.bytes

type: long

Expand All @@ -2170,14 +2162,14 @@ Old collection gc.


[float]
=== elasticsearch.node_stats.jvm.gc.collectors.old.collection.count
=== elasticsearch.node.stats.jvm.gc.collectors.old.collection.count

type: long



[float]
=== elasticsearch.node_stats.jvm.gc.collectors.old.collection.ms
=== elasticsearch.node.stats.jvm.gc.collectors.old.collection.ms

type: long

Expand All @@ -2191,14 +2183,14 @@ Young collection gc.


[float]
=== elasticsearch.node_stats.jvm.gc.collectors.young.collection.count
=== elasticsearch.node.stats.jvm.gc.collectors.young.collection.count

type: long



[float]
=== elasticsearch.node_stats.jvm.gc.collectors.young.collection.ms
=== elasticsearch.node.stats.jvm.gc.collectors.young.collection.ms

type: long

Expand Down
10 changes: 8 additions & 2 deletions metricbeat/mb/mb.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ import (
)

const (
// ModuleData is the key used in events created by MetricSets to add data
// ModuleDataKey is the key used in events created by MetricSets to add data
// to an event that is common to the module. The data must be a
// common.MapStr and when the final event is built the object will be stored
// in the event under a key that is the module name.
ModuleData string = "_module"
ModuleDataKey string = "_module"

// NamespaceKey is used to define a different namespace for the metricset
// This is useful for dynamic metricsets or metricsets which do not
// put the name under the same name as the package. This is for example
// the case in elasticsearch `node_stats` which puts the data under `node.stats`.
NamespaceKey string = "_namespace"
)

// Module interfaces
Expand Down
86 changes: 24 additions & 62 deletions metricbeat/mb/module/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import (
"github.com/elastic/beats/metricbeat/mb"
)

const (
defaultType = "metricsets"
)

// EventBuilder is used for building MetricSet events. MetricSets generate a
// data in the form of a common.MapStr. This builder transforms that data into
// a complete event and applies any Module-level filtering.
Expand All @@ -38,8 +34,6 @@ func (b EventBuilder) Build() (common.MapStr, error) {
}

// Get and remove meta fields from the event created by the MetricSet.
indexName := getIndex(event, "")
typeName := getType(event, defaultType)
timestamp := getTimestamp(event, common.Time(b.StartTime))

// Apply filters.
Expand All @@ -49,56 +43,51 @@ func (b EventBuilder) Build() (common.MapStr, error) {
}
}

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

metricsetData := common.MapStr{
"module": b.ModuleName,
"name": b.MetricSetName,
}
// Adds host name to event.
if b.Host != "" {
metricsetData["host"] = b.Host
}
if b.FetchDuration != 0 {
metricsetData["rtt"] = b.FetchDuration.Nanoseconds() / int64(time.Microsecond)
}

namespace := b.MetricSetName
if n, ok := event["_namespace"]; ok {
delete(event, "_namespace")
namespace = n.(string)
// TODO: check if namespace does not already exist
if ns, ok := n.(string); ok {
namespace = ns
}

metricsetData["namespace"] = namespace
}

event = common.MapStr{
"@timestamp": timestamp,
"type": typeName,
common.EventMetadataKey: b.metadata,
b.ModuleName: common.MapStr{
namespace: event,
},
"metricset": metricsetData,
// Checks if additional meta information is provided by the MetricSet under the key ModuleData
// This is based on the convention that each MetricSet can provide module data under the key ModuleData
moduleData, moudleDataExists := event[mb.ModuleDataKey]
if moudleDataExists {
delete(event, mb.ModuleDataKey)
}

moduleEvent := common.MapStr{}
moduleEvent.Put(namespace, event)

// In case meta data exists, it is added on the module level
// This is mostly used for shared fields across multiple metricsets in one module
if moudleDataExists {
if _, ok := moduleData.(common.MapStr); ok {
event[b.ModuleName].(common.MapStr).Update(moduleData.(common.MapStr))
}
}

// Overwrite default index if set.
if indexName != "" {
event["beat"] = common.MapStr{
"index": indexName,
if data, ok := moduleData.(common.MapStr); ok {
moduleEvent.DeepUpdate(data)
}
}

// Adds host name to event.
if b.Host != "" {
event["metricset"].(common.MapStr)["host"] = b.Host
event = common.MapStr{
"@timestamp": timestamp,
common.EventMetadataKey: b.metadata,
b.ModuleName: moduleEvent,
"metricset": metricsetData,
}

// Adds error to event in case error happened
Expand All @@ -111,33 +100,6 @@ func (b EventBuilder) Build() (common.MapStr, error) {
return event, nil
}

func getIndex(event common.MapStr, indexName string) string {
// Set index from event if set

if _, ok := event["index"]; ok {
indexName, ok = event["index"].(string)
if !ok {
logp.Err("Index couldn't be overwritten because event index is not string")
}
delete(event, "index")
}
return indexName
}

func getType(event common.MapStr, typeName string) string {

// Set type from event if set
if _, ok := event["type"]; ok {
typeName, ok = event["type"].(string)
if !ok {
logp.Err("Type couldn't be overwritten because event type is not string")
}
delete(event, "type")
}

return typeName
}

func getTimestamp(event common.MapStr, timestamp common.Time) common.Time {

// Set timestamp from event if set, move it to the top level
Expand Down
1 change: 0 additions & 1 deletion metricbeat/mb/module/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func TestEventBuilder(t *testing.T) {
t.Fatal(err)
}

assert.Equal(t, defaultType, event["type"])
assert.Equal(t, common.Time(startTime), event["@timestamp"])

metricset := event["metricset"].(common.MapStr)
Expand Down
3 changes: 1 addition & 2 deletions metricbeat/mb/module/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ func ExampleWrapper() {
// "module": "fake",
// "name": "eventfetcher",
// "rtt": 111
// },
// "type": "metricsets"
// }
// }
}

Expand Down
Loading