-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
358 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//// | ||
This file is generated! See scripts/docs_collector.py | ||
//// | ||
|
||
[[metricbeat-module-dropwizard]] | ||
== dropwizard Module | ||
|
||
This is the dropwizard Module. | ||
|
||
|
||
|
||
[float] | ||
=== Example Configuration | ||
|
||
The Dropwizard module supports the standard configuration options that are described | ||
in <<configuration-metricbeat>>. Here is an example configuration: | ||
|
||
[source,yaml] | ||
---- | ||
metricbeat.modules: | ||
#- module: dropwizard | ||
#metricsets: ["collector"] | ||
#enabled: true | ||
#period: 10s | ||
#hosts: ["localhost:8080"] | ||
#metrics_path: /metrics/metrics | ||
#namespace: example | ||
---- | ||
|
||
[float] | ||
=== Metricsets | ||
|
||
The following metricsets are available: | ||
|
||
* <<metricbeat-metricset-dropwizard-collector,collector>> | ||
|
||
include::dropwizard/collector.asciidoc[] | ||
|
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-dropwizard-collector]] | ||
include::../../../module/dropwizard/collector/_meta/docs.asciidoc[] | ||
|
||
|
||
==== Fields | ||
|
||
For a description of each field in the metricset, see the | ||
<<exported-fields-dropwizard,exported fields>> section. | ||
|
||
Here is an example document generated by this metricset: | ||
|
||
[source,json] | ||
---- | ||
include::../../../module/dropwizard/collector/_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,7 @@ | ||
#- module: dropwizard | ||
#metricsets: ["collector"] | ||
#enabled: true | ||
#period: 10s | ||
#hosts: ["localhost:8080"] | ||
#metrics_path: /metrics/metrics | ||
#namespace: example |
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,4 @@ | ||
== dropwizard Module | ||
|
||
This is the dropwizard Module. | ||
|
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,12 @@ | ||
- key: dropwizard | ||
title: "Dropwizard" | ||
description: > | ||
beta[] | ||
Stats collected from Dropwizard. | ||
short_config: false | ||
fields: | ||
- name: dropwizard | ||
type: group | ||
description: > | ||
fields: |
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,29 @@ | ||
{ | ||
"@timestamp": "2017-04-16T06:42:37.441Z", | ||
"beat": { | ||
"hostname": "beathost", | ||
"name": "beathost", | ||
"version": "6.0.0-alpha1" | ||
}, | ||
"dropwizard": { | ||
"test": { | ||
"counter1": { | ||
"count": 1337 | ||
}, | ||
"gauge1": { | ||
"value": 1337 | ||
}, | ||
"tags": { | ||
"this": "that" | ||
} | ||
} | ||
}, | ||
"metricset": { | ||
"host": "localhost:8080", | ||
"module": "dropwizard", | ||
"name": "collector", | ||
"namespace": "test", | ||
"rtt": 8008 | ||
}, | ||
"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 @@ | ||
=== dropwizard collector MetricSet | ||
|
||
This is the collector metricset of the module dropwizard. |
Empty file.
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,94 @@ | ||
package collector | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/elastic/beats/libbeat/common" | ||
"github.com/elastic/beats/libbeat/logp" | ||
"github.com/elastic/beats/metricbeat/helper" | ||
"github.com/elastic/beats/metricbeat/mb" | ||
"github.com/elastic/beats/metricbeat/mb/parse" | ||
"strings" | ||
) | ||
|
||
const ( | ||
defaultScheme = "http" | ||
defaultPath = "/metrics/metrics" | ||
) | ||
|
||
var ( | ||
hostParser = parse.URLHostParserBuilder{ | ||
DefaultScheme: defaultScheme, | ||
DefaultPath: defaultPath, | ||
PathConfigKey: "metrics_path", | ||
}.Build() | ||
) | ||
|
||
// 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("dropwizard", "collector", New, hostParser); 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 | ||
http *helper.HTTP | ||
namespace string | ||
} | ||
|
||
// 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("BETA: The dropwizard collector metricset is beta") | ||
config := struct { | ||
Namespace string `config:"namespace" validate:"required"` | ||
}{} | ||
|
||
if err := base.Module().UnpackConfig(&config); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &MetricSet{ | ||
BaseMetricSet: base, | ||
http: helper.NewHTTP(base), | ||
namespace: config.Namespace, | ||
}, 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) { | ||
body, err := m.http.FetchContent() | ||
if err != nil { | ||
return nil, err | ||
} | ||
dw := map[string]interface{}{} | ||
|
||
d := json.NewDecoder(strings.NewReader(string(body))) | ||
d.UseNumber() | ||
|
||
err = d.Decode(&dw) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
eventList := eventMapping(dw) | ||
|
||
// Converts hash list to slice | ||
events := []common.MapStr{} | ||
for _, e := range eventList { | ||
e["_namespace"] = m.namespace | ||
events = append(events, e) | ||
} | ||
|
||
return events, err | ||
|
||
} |
Oops, something went wrong.