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

[Metricbeat] Move statsd metricbeat module to GA #16447

Merged
merged 8 commits into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 2 additions & 1 deletion CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Add MQTT input. {issue}15602[15602] {pull}16204[16204]
- Add ECS categorization fields to activemq module. {issue}16151[16151] {pull}16201[16201]
- Add a TLS test and more debug output to httpjson input {pull}16315[16315]
- Add an SSL config example in config.yml for filebeat MISP module. {pull}16320[16320]
- Add an SSL config example in config.yml for filebeat MISP module. {pull}16320[16320]
- Improve ECS categorization, container & process field mappings in auditd module. {issue}16153[16153] {pull}16280[16280]

*Heartbeat*
Expand Down Expand Up @@ -164,6 +164,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Add Load Balancing metricset to GCP {pull}15559[15559]
- Add support for Dropwizard metrics 4.1. {pull}16332[16332]
- Improve the `haproxy` module to support metrics exposed via HTTPS. {issue}14579[14579] {pull}16333[16333]
- Release `statsd` module as GA. {pull}16447[16447] {issue}14280[14280]

*Packetbeat*

Expand Down
79 changes: 77 additions & 2 deletions metricbeat/docs/modules/statsd.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,85 @@ This file is generated! See scripts/mage/docs_collector.go
[role="xpack"]
== Statsd module

beta[]
[role="xpack"]
== Statsd module

The `statsd` module is a Metricbeat module which spawns a UDP server and listens for metrics in StatsD compatible
format.

[float]
=== Metric types

The module supports the following types of metrics:

*Counter (c)*:: Measurement which accumulates over period of time until flushed (value set to 0).

*Gauge (g)*:: Measurement which can increase, decrease or be set to a value.

*Timer (ms)*:: Time measurement (in milliseconds) of an event.

*Histogram (h)*:: Time measurement, alias for timer.

The Statsd module is a Metricbeat module which opens a UDP port and listens for statsd metrics.
*Set (s)*:: Measurement which counts unique occurrences until flushed (value set to 0).

[float]
=== Configuration options

This module has some configuration options for controlling its behavior. The
following example shows all configuration options.

[source,yaml]
----
- module: statsd
metricsets: ["server"]
host: "localhost"
port: "8125"
#ttl: "30s"
----

This module also supports the
<<module-standard-options-{modulename},standard configuration options>>
described later.

*`ttl`*:: It defines how long a metric will be reported after it was last recorded.
Irrespective of the given ttl, metrics will be reported at least once.
A ttl of zero means metrics will never expire.

include::{docdir}/metricbeat-options.asciidoc[]

[float]
=== Metricsets

Currently, there is only `server` metricset in `statsd` module.

[float]
==== `server`
The metricset collects metric data sent using UDP and publishes them under the `statsd` prefix.

[float]
=== Development

Run metricbeat locally with configured `statsd` module. Use favorite statsd client to emit metrics, e.g.:

[source,shell script]
----
$ npm install statsd-client
$ node
----

Emit some metrics:

[source,javascript]
----
let SDC = require('statsd-client'), sdc = new SDC({host: 'localhost', port: 8125});
sdc.increment('systemname.subsystem.value');
sdc.gauge('what.you.gauge', 100);
sdc.gaugeDelta('what.you.gauge', -70);
sdc.gauge('gauge.with.tags', 100, {foo: 'bar'});
sdc.set('set.with.tags', 100, {foo: 'bar'});
sdc.set('set.with.tags', 200, {foo: 'bar'});
sdc.set('set.with.tags', 100, {foo: 'baz'});
----


[float]
Expand Down
2 changes: 0 additions & 2 deletions metricbeat/docs/modules/statsd/server.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ This file is generated! See scripts/mage/docs_collector.go
[[metricbeat-metricset-statsd-server]]
=== Statsd server metricset

beta[]

include::../../../../x-pack/metricbeat/module/statsd/server/_meta/docs.asciidoc[]

This is a default metricset. If the host module is unconfigured, this metricset is enabled by default.
Expand Down
4 changes: 2 additions & 2 deletions metricbeat/docs/modules_list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ This file is generated! See scripts/mage/docs_collector.go
.3+| .3+| |<<metricbeat-metricset-stan-channels,channels>> beta[]
|<<metricbeat-metricset-stan-stats,stats>> beta[]
|<<metricbeat-metricset-stan-subscriptions,subscriptions>> beta[]
|<<metricbeat-module-statsd,Statsd>> beta[] |image:./images/icon-no.png[No prebuilt dashboards] |
.1+| .1+| |<<metricbeat-metricset-statsd-server,server>> beta[]
|<<metricbeat-module-statsd,Statsd>> |image:./images/icon-no.png[No prebuilt dashboards] |
.1+| .1+| |<<metricbeat-metricset-statsd-server,server>>
|<<metricbeat-module-system,System>> |image:./images/icon-yes.png[Prebuilt dashboards are available] |
.17+| .17+| |<<metricbeat-metricset-system-core,core>>
|<<metricbeat-metricset-system-cpu,cpu>>
Expand Down
37 changes: 0 additions & 37 deletions x-pack/metricbeat/module/statsd/README.md

This file was deleted.

79 changes: 78 additions & 1 deletion x-pack/metricbeat/module/statsd/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
@@ -1,2 +1,79 @@
The Statsd module is a Metricbeat module which opens a UDP port and listens for statsd metrics.
[role="xpack"]
== Statsd module

The `statsd` module is a Metricbeat module which spawns a UDP server and listens for metrics in StatsD compatible
format.

[float]
=== Metric types

The module supports the following types of metrics:

*Counter (c)*:: Measurement which accumulates over period of time until flushed (value set to 0).

*Gauge (g)*:: Measurement which can increase, decrease or be set to a value.

*Timer (ms)*:: Time measurement (in milliseconds) of an event.

*Histogram (h)*:: Time measurement, alias for timer.

*Set (s)*:: Measurement which counts unique occurrences until flushed (value set to 0).

[float]
=== Configuration options

This module has some configuration options for controlling its behavior. The
following example shows all configuration options.

[source,yaml]
----
- module: statsd
metricsets: ["server"]
host: "localhost"
port: "8125"
#ttl: "30s"
----

This module also supports the
<<module-standard-options-{modulename},standard configuration options>>
described later.

*`ttl`*:: It defines how long a metric will be reported after it was last recorded.
Irrespective of the given ttl, metrics will be reported at least once.
A ttl of zero means metrics will never expire.

include::{docdir}/metricbeat-options.asciidoc[]

[float]
=== Metricsets

Currently, there is only `server` metricset in `statsd` module.

[float]
==== `server`
The metricset collects metric data sent using UDP and publishes them under the `statsd` prefix.

[float]
=== Development
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think development notes should be in a README.md instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


Run metricbeat locally with configured `statsd` module. Use favorite statsd client to emit metrics, e.g.:

[source,shell script]
----
$ npm install statsd-client
$ node
----

Emit some metrics:

[source,javascript]
----
let SDC = require('statsd-client'), sdc = new SDC({host: 'localhost', port: 8125});
sdc.increment('systemname.subsystem.value');
sdc.gauge('what.you.gauge', 100);
sdc.gaugeDelta('what.you.gauge', -70);
sdc.gauge('gauge.with.tags', 100, {foo: 'bar'});
sdc.set('set.with.tags', 100, {foo: 'bar'});
sdc.set('set.with.tags', 200, {foo: 'bar'});
sdc.set('set.with.tags', 100, {foo: 'baz'});
----
2 changes: 1 addition & 1 deletion x-pack/metricbeat/module/statsd/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: "Statsd"
description: >
Statsd module
release: beta
release: ga
fields:
- name: statsd
type: group
Expand Down
2 changes: 1 addition & 1 deletion x-pack/metricbeat/module/statsd/fields.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 2 additions & 16 deletions x-pack/metricbeat/module/statsd/server/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
This is the server metricset of the statsd module.

Events sent to the stats endpoint will be put by default under the `statsd` prefix.

_ttl_ defines how long a metric will be reported after it was last recorded.
Irrespective of the given ttl, metrics will be reported at least once.
A ttl of zero means metrics will never expire.

["source","yaml",subs="attributes"]
------------------------------------------------------------------------------
- module: statsd
metricsets: ["server"]
host: "localhost"
port: "8125"
#ttl: "30s"
------------------------------------------------------------------------------
[role="xpack"]

This is the `server` metricset of the `statsd` module.
2 changes: 1 addition & 1 deletion x-pack/metricbeat/module/statsd/server/_meta/fields.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- release: beta
- release: ga
46 changes: 46 additions & 0 deletions x-pack/metricbeat/module/statsd/test_statsd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import os
import socket
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), '../../tests/system'))
from xpack_metricbeat import XPackTest, metricbeat

STATSD_HOST = '127.0.0.1'
STATSD_PORT = 8125

METRIC_MESSAGE = bytes('metric1:777.0|g|#k1:v1,k2:v2', 'utf-8')


class Test(XPackTest):

def test_server(self):
"""
statsd server metricset test
"""

# Start the application
self.render_config_template(modules=[{
"name": "statsd",
"metricsets": ["server"],
"period": "5s",
"host": STATSD_HOST,
"port": STATSD_PORT,
}])
proc = self.start_beat()
self.wait_until(lambda: self.log_contains("Started listening for UDP"))

# Send UDP packet with metric
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(METRIC_MESSAGE, (STATSD_HOST, STATSD_PORT))
sock.close()

self.wait_until(lambda: self.output_lines() > 0)
proc.check_kill_and_wait()
self.assert_no_logged_warnings(replace='use of closed network connection')

# Verify output
output = self.read_output_json()
self.assertGreater(len(output), 0)
evt = output[0]
assert evt["statsd"]["metric1"]["value"] == 777
self.assert_fields_are_documented(evt)