Skip to content

Commit

Permalink
Adding dropwizard module
Browse files Browse the repository at this point in the history
  • Loading branch information
vjsamuel committed Apr 16, 2017
1 parent a9b5334 commit 564a0ec
Show file tree
Hide file tree
Showing 15 changed files with 358 additions and 0 deletions.
14 changes: 14 additions & 0 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ grouped in the following categories:
* <<exported-fields-common>>
* <<exported-fields-couchbase>>
* <<exported-fields-docker>>
* <<exported-fields-dropwizard>>
* <<exported-fields-elasticsearch>>
* <<exported-fields-golang>>
* <<exported-fields-haproxy>>
Expand Down Expand Up @@ -1875,6 +1876,19 @@ type: long
Total number of outgoing packets.
[[exported-fields-dropwizard]]
== Dropwizard Fields
beta[]
Stats collected from Dropwizard.
[float]
== dropwizard Fields
[[exported-fields-elasticsearch]]
== elasticsearch Fields
Expand Down
38 changes: 38 additions & 0 deletions metricbeat/docs/modules/dropwizard.asciidoc
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[]

19 changes: 19 additions & 0 deletions metricbeat/docs/modules/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[]
----
2 changes: 2 additions & 0 deletions metricbeat/docs/modules_list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This file is generated! See scripts/docs_collector.py
* <<metricbeat-module-ceph,ceph>>
* <<metricbeat-module-couchbase,Couchbase>>
* <<metricbeat-module-docker,Docker>>
* <<metricbeat-module-dropwizard,Dropwizard>>
* <<metricbeat-module-elasticsearch,elasticsearch>>
* <<metricbeat-module-golang,golang>>
* <<metricbeat-module-haproxy,HAProxy>>
Expand All @@ -32,6 +33,7 @@ include::modules/apache.asciidoc[]
include::modules/ceph.asciidoc[]
include::modules/couchbase.asciidoc[]
include::modules/docker.asciidoc[]
include::modules/dropwizard.asciidoc[]
include::modules/elasticsearch.asciidoc[]
include::modules/golang.asciidoc[]
include::modules/haproxy.asciidoc[]
Expand Down
2 changes: 2 additions & 0 deletions metricbeat/include/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
_ "github.com/elastic/beats/metricbeat/module/docker/info"
_ "github.com/elastic/beats/metricbeat/module/docker/memory"
_ "github.com/elastic/beats/metricbeat/module/docker/network"
_ "github.com/elastic/beats/metricbeat/module/dropwizard"
_ "github.com/elastic/beats/metricbeat/module/dropwizard/collector"
_ "github.com/elastic/beats/metricbeat/module/elasticsearch"
_ "github.com/elastic/beats/metricbeat/module/elasticsearch/node"
_ "github.com/elastic/beats/metricbeat/module/elasticsearch/node_stats"
Expand Down
9 changes: 9 additions & 0 deletions metricbeat/metricbeat.full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ metricbeat.modules:
#certificate: "/etc/pki/client/cert.pem"
#key: "/etc/pki/client/cert.key"

#----------------------------- Dropwizard Module -----------------------------
#- module: dropwizard
#metricsets: ["collector"]
#enabled: true
#period: 10s
#hosts: ["localhost:8080"]
#metrics_path: /metrics/metrics
#namespace: example

#---------------------------- elasticsearch Module ---------------------------
#- module: elasticsearch
# metricsets: ["node", "node_stats", "stats"]
Expand Down
7 changes: 7 additions & 0 deletions metricbeat/module/dropwizard/_meta/config.yml
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
4 changes: 4 additions & 0 deletions metricbeat/module/dropwizard/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
== dropwizard Module

This is the dropwizard Module.

12 changes: 12 additions & 0 deletions metricbeat/module/dropwizard/_meta/fields.yml
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:
29 changes: 29 additions & 0 deletions metricbeat/module/dropwizard/collector/_meta/data.json
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"
}
3 changes: 3 additions & 0 deletions metricbeat/module/dropwizard/collector/_meta/docs.asciidoc
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.
94 changes: 94 additions & 0 deletions metricbeat/module/dropwizard/collector/collector.go
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

}
Loading

0 comments on commit 564a0ec

Please sign in to comment.