-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Adding dropwizard module #4022
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
Adding dropwizard module #4022
Changes from 2 commits
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,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[] | ||
|
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[] | ||
---- |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM golang:1.7 | ||
RUN apt-get update && apt-get install curl | ||
COPY main.go /go | ||
|
||
HEALTHCHECK CMD curl -f http://localhost:9090/metrics/metrics | ||
EXPOSE 9090 | ||
|
||
CMD go run /go/main.go |
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
== dropwizard Module | ||
|
||
This is the dropwizard Module. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
DROPWIZARD_HOST=dropwizard | ||
DROPWIZARD_PORT=9090 |
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: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/http" | ||
) | ||
|
||
var response = `{"version":"4.0.0","gauges":{"my_gauge{this=that}":{"value":565}},"counters":{"my_counter":{"count":565},"my_counter2{this=that}":{"count":565}},"histograms":{"my_hist":{"count":565,"max":564,"mean":563.3148706761577,"min":0,"p50":564.0,"p75":564.0,"p95":564.0,"p98":564.0,"p99":564.0,"p999":564.0,"stddev":1.0747916190718627}},"meters":{"my_meter":{"count":0,"m1_rate":0.0,"m5_rate":0.0,"m15_rate":0.0,"mean_rate":0.0,"units":"events/second"}},"timers":{"my_timer{this=that}":{"count":0,"max":0.0,"mean":0.0,"min":0.0,"p50":0.0,"p75":0.0,"p95":0.0,"p98":0.0,"p99":0.0,"p999":0.0,"stddev":0.0,"m1_rate":0.0,"m5_rate":0.0,"m15_rate":0.0,"mean_rate":0.0,"duration_units":"seconds","rate_units":"calls/second"}}}` | ||
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. For testing the JSON output we don't need the integration tests. We could also do this with eventMapping and just load the content. I would like to have a docker environment with a real dropwizard app inside (if possible). So in case things break, we have an instance around to test and don't have to build one ourself. 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. added a proper dropwizard http endpoint as part of the integration run. |
||
|
||
func sendResponse(w http.ResponseWriter, r *http.Request) { | ||
fmt.Fprintf(w, response) | ||
} | ||
|
||
func main() { | ||
|
||
http.HandleFunc("/metrics/metrics", sendResponse) // set router | ||
err := http.ListenAndServe(":9090", nil) // set listen port | ||
if err != nil { | ||
log.Fatal("ListenAndServe: ", err) | ||
} | ||
} |
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": { | ||
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. As it is a "dynamic" metricset I'm a bit undecided what we should do here. In other dynamic metricsets we leave it empty here (https://github.com/elastic/beats/blob/master/metricbeat/module/windows/perfmon/_meta/data.json) but provide an example output in the docs. 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. removed the custom metrics |
||
"counter1": { | ||
"count": 1337 | ||
}, | ||
"gauge1": { | ||
"value": 1337 | ||
}, | ||
"tags": { | ||
"this": "that" | ||
} | ||
} | ||
}, | ||
"metricset": { | ||
"host": "localhost:8080", | ||
"module": "dropwizard", | ||
"name": "collector", | ||
"namespace": "test", | ||
"rtt": 8008 | ||
}, | ||
"type": "metricsets" | ||
} |
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. |
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.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() | ||
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. Interesting. Is there something special about the floats returned so we need this? 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. yes. if not everything gets written out as double values. |
||
|
||
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 | ||
|
||
} |
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.
Could you add a link to dropwizard here?
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.
done.