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 module for Traefik #7413

Merged
merged 49 commits into from
Jul 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
4ac476a
Init checkin
ycombinator Jun 26, 2018
07afa97
Publishing uptime.sec
ycombinator Jun 26, 2018
1da6229
Adding field to fields.yml; adding data.go
ycombinator Jun 26, 2018
6abccaf
Fixing imports formatting
ycombinator Jun 26, 2018
897f576
Adding more metrics
ycombinator Jun 26, 2018
102e5e7
Adding header
ycombinator Jun 26, 2018
1349b5f
Updating generated assets
ycombinator Jun 26, 2018
d16cec2
Updating descriptions in field.yml files
ycombinator Jun 27, 2018
4d85bf2
Fleshing out doc
ycombinator Jun 27, 2018
9e9d51d
Adding healthcheck
ycombinator Jun 27, 2018
caeee0c
Change uptime type to int (was float)
ycombinator Jun 27, 2018
acb87e4
Starting to add unit tests
ycombinator Jun 27, 2018
a0c4b10
Unit tests
ycombinator Jun 27, 2018
70b00ff
Adding entry to CHANGELOG
ycombinator Jun 27, 2018
56b8927
Adding integration tests
ycombinator Jun 27, 2018
a76b7c7
Fixing function name duplication
ycombinator Jun 27, 2018
fe0c7fc
Fixing health check URL in Dockerfile
ycombinator Jun 28, 2018
932073d
Adding flags to unit test files for skipping them during integration …
ycombinator Jun 28, 2018
ff5c8a2
Adding system test file (WIP)
ycombinator Jun 28, 2018
7584cf8
Fixing system test
ycombinator Jun 28, 2018
b67847f
Update Dockerfile
ycombinator Jun 28, 2018
de9c972
Use new interfaces
ycombinator Jun 28, 2018
fe80d57
Updating fields.go
ycombinator Jun 28, 2018
b027607
Fixing location of CHANGELOG entry
ycombinator Jun 28, 2018
7650731
Updating data.json
ycombinator Jun 28, 2018
48490e9
Using shorter syntax for describing uptime.sec field
ycombinator Jun 28, 2018
8998c45
Changing datatype of average response time to microseconds
ycombinator Jun 28, 2018
bd131f7
Updating schema for response counts per status code
ycombinator Jun 28, 2018
41ab4de
Regenerating sample ES document
ycombinator Jun 28, 2018
89b99b5
Store status code counts as ints
ycombinator Jun 28, 2018
2cc6ac6
Actually make a request to the proxy and then assert on its effects
ycombinator Jun 28, 2018
c4f6ade
Fiddling with data types
ycombinator Jun 28, 2018
f0ab0eb
Extract mock response into test fixture file
ycombinator Jun 28, 2018
6292c7f
Moving system test file into module folder
ycombinator Jun 28, 2018
03d6a9f
Simplifying using helper method
ycombinator Jun 28, 2018
a0b5191
Missed an import in the system test script
ycombinator Jun 28, 2018
d9ec2fb
Forgot to define FIELDS
ycombinator Jun 28, 2018
bed5d3c
Copy pasta fail :(
ycombinator Jun 28, 2018
69e433a
Augmenting import path before importing metricbeat
ycombinator Jun 29, 2018
2f26d10
Fixing up formatting
ycombinator Jun 29, 2018
3b0ef8b
Missed an import
ycombinator Jun 29, 2018
249f97f
Adding guard clause
ycombinator Jun 29, 2018
072dda2
Renaming status code field
ycombinator Jun 29, 2018
32a2914
Adding service.name field
ycombinator Jun 29, 2018
5fb7c35
Move testing config functions into mtest package
ycombinator Jun 29, 2018
51d1f37
Using MapStr.Put to crete service.name nested field
ycombinator Jun 29, 2018
44d4e60
Removing unnecessary newline
ycombinator Jul 2, 2018
5295345
Shortening comments
ycombinator Jul 2, 2018
bb54c34
Check that type assertion works
ycombinator Jul 2, 2018
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 @@ -288,6 +288,7 @@ https://github.com/elastic/beats/compare/v6.2.3...master[Check the HEAD diff]
- Update `state_container` metricset to support latest `kube-state-metrics` version. {pull}7216[7216]
- Collect accumulated docker network metrics and mark old ones as deprecated. {pull}7253[7253]
- Add TLS support to MongoDB module. {pull}7401[7401]
- Added Traefik module with health metricset. {pull}7413[7413]

*Packetbeat*

Expand Down
4 changes: 4 additions & 0 deletions metricbeat/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ services:
- ./module/prometheus/_meta/env
- ./module/rabbitmq/_meta/env
- ./module/redis/_meta/env
- ./module/traefik/_meta/env
- ./module/uwsgi/_meta/env
- ./module/zookeeper/_meta/env

Expand Down Expand Up @@ -147,6 +148,9 @@ services:
redis:
build: ./module/redis/_meta

traefik:
build: ./module/traefik/_meta

uwsgi_tcp:
build: ./module/uwsgi/_meta
command: uwsgi --http :8080 --master --processes 1 --threads 2 --stats 0.0.0.0:9191 --memory-report --wsgi-file app.py
Expand Down
69 changes: 69 additions & 0 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ grouped in the following categories:
* <<exported-fields-rabbitmq>>
* <<exported-fields-redis>>
* <<exported-fields-system>>
* <<exported-fields-traefik>>
* <<exported-fields-uwsgi>>
* <<exported-fields-vsphere>>
* <<exported-fields-windows>>
Expand Down Expand Up @@ -16414,6 +16415,74 @@ format: duration
The OS uptime in milliseconds.


--

[[exported-fields-traefik]]
== traefik fields

Traefik reverse proxy / load balancer metrics



[float]
== traefik fields

Traefik reverse proxy / load balancer metrics



[float]
== health fields

Metrics obtained from Traefik's health API endpoint



*`traefik.health.uptime.sec`*::
+
--
type: long

Uptime of Traefik instance in seconds


--

[float]
== response fields

Response metrics



*`traefik.health.response.count`*::
+
--
type: long

Number of responses


--

*`traefik.health.response.avg_time.us`*::
+
--
type: long

Average response time in microseconds


--

*`traefik.health.response.status_code`*::
+
--
type: object

Number of responses per status code


--

[[exported-fields-uwsgi]]
Expand Down
41 changes: 41 additions & 0 deletions metricbeat/docs/modules/traefik.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
////
This file is generated! See scripts/docs_collector.py
////

[[metricbeat-module-traefik]]
== traefik module

experimental[]

This module periodically fetches metrics from a https://traefik.io/[Traefik]
instance. The Traefik instance must be configured to expose it's HTTP API.

=== Compatibility

The Traefik metricsets were tested with Traefik 1.6.


[float]
=== Example configuration

The traefik module supports the standard configuration options that are described
in <<configuration-metricbeat>>. Here is an example configuration:

[source,yaml]
----
metricbeat.modules:
- module: traefik
metricsets: ["health"]
period: 10s
hosts: ["localhost:8080"]
----

[float]
=== Metricsets

The following metricsets are available:

* <<metricbeat-metricset-traefik-health,health>>

include::traefik/health.asciidoc[]

23 changes: 23 additions & 0 deletions metricbeat/docs/modules/traefik/health.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
////
This file is generated! See scripts/docs_collector.py
////

[[metricbeat-metricset-traefik-health]]
=== traefik health metricset

experimental[]

include::../../../module/traefik/health/_meta/docs.asciidoc[]


==== Fields

For a description of each field in the metricset, see the
<<exported-fields-traefik,exported fields>> section.

Here is an example document generated by this metricset:

[source,json]
----
include::../../../module/traefik/health/_meta/data.json[]
----
3 changes: 3 additions & 0 deletions metricbeat/docs/modules_list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ This file is generated! See scripts/docs_collector.py
|<<metricbeat-metricset-system-raid,raid>> beta[]
|<<metricbeat-metricset-system-socket,socket>> beta[]
|<<metricbeat-metricset-system-uptime,uptime>>
|<<metricbeat-module-traefik,traefik>> experimental[] |image:./images/icon-no.png[No prebuilt dashboards] |
.1+| .1+| |<<metricbeat-metricset-traefik-health,health>> experimental[]
|<<metricbeat-module-uwsgi,uwsgi>> beta[] |image:./images/icon-yes.png[Prebuilt dashboards are available] |
.1+| .1+| |<<metricbeat-metricset-uwsgi-status,status>> beta[]
|<<metricbeat-module-vsphere,vSphere>> beta[] |image:./images/icon-no.png[No prebuilt dashboards] |
Expand Down Expand Up @@ -169,6 +171,7 @@ include::modules/prometheus.asciidoc[]
include::modules/rabbitmq.asciidoc[]
include::modules/redis.asciidoc[]
include::modules/system.asciidoc[]
include::modules/traefik.asciidoc[]
include::modules/uwsgi.asciidoc[]
include::modules/vsphere.asciidoc[]
include::modules/windows.asciidoc[]
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/include/fields.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions metricbeat/include/list.go

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

6 changes: 6 additions & 0 deletions metricbeat/metricbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,12 @@ metricbeat.modules:
# Redis AUTH password. Empty by default.
#password: foobared

#------------------------------- traefik Module ------------------------------
- module: traefik
metricsets: ["health"]
period: 10s
hosts: ["localhost:8080"]

#-------------------------------- uwsgi Module -------------------------------
- module: uwsgi
metricsets: ["status"]
Expand Down
6 changes: 6 additions & 0 deletions metricbeat/module/traefik/_meta/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM traefik:1.6-alpine

COPY ./traefik.toml /etc/traefik/traefik.toml

RUN apk add --no-cache curl
HEALTHCHECK --interval=1s --retries=90 CMD curl -f http://localhost:8080/health
4 changes: 4 additions & 0 deletions metricbeat/module/traefik/_meta/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- module: traefik
metricsets: ["health"]
period: 10s
hosts: ["localhost:8080"]
6 changes: 6 additions & 0 deletions metricbeat/module/traefik/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This module periodically fetches metrics from a https://traefik.io/[Traefik]
instance. The Traefik instance must be configured to expose it's HTTP API.

=== Compatibility

The Traefik metricsets were tested with Traefik 1.6.
2 changes: 2 additions & 0 deletions metricbeat/module/traefik/_meta/env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
TRAEFIK_HOST=traefik
TRAEFIK_API_PORT=8080
10 changes: 10 additions & 0 deletions metricbeat/module/traefik/_meta/fields.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- key: traefik
title: "traefik"
description: >
Traefik reverse proxy / load balancer metrics
fields:
- name: traefik
type: group
description: >
Traefik reverse proxy / load balancer metrics
fields:
1 change: 1 addition & 0 deletions metricbeat/module/traefik/_meta/traefik.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[api]
19 changes: 19 additions & 0 deletions metricbeat/module/traefik/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

// Package traefik is a Metricbeat module that contains MetricSets.
package traefik
29 changes: 29 additions & 0 deletions metricbeat/module/traefik/health/_meta/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is the purpose of this file? How is it used?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is an example output document that we should in the docs. It is generated by this command here: https://github.com/elastic/beats/blob/master/metricbeat/Makefile#L73 As this updates all data.json I normally run the following command:

go test -tags=integration github.com/elastic/beats/metricbeat/module/traefik/... -data

In you case this assumes the traefik docker container is running and exposes the port on localhost. This will generate a data.json file and make update will link it in the docs.

Here you can see an example in the docs: https://www.elastic.co/guide/en/beats/metricbeat/master/metricbeat-metricset-elasticsearch-index.html

"@timestamp": "2017-10-12T08:05:34.853Z",
"beat": {
"hostname": "host.example.com",
"name": "host.example.com"
},
"metricset": {
"host": "127.0.0.1:8080",
"module": "traefik",
"name": "health",
"rtt": 115
},
"traefik": {
"health": {
"response": {
"avg_time": {
"us": 32
},
"count": 15,
"status_codes": {
"404": 15
}
},
"uptime": {
"sec": 1944
}
}
}
}
3 changes: 3 additions & 0 deletions metricbeat/module/traefik/health/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
=== traefik health MetricSet

This is the health metricset of the module traefik.
27 changes: 27 additions & 0 deletions metricbeat/module/traefik/health/_meta/fields.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
- name: health
type: group
description: >
Metrics obtained from Traefik's health API endpoint
fields:
- name: uptime.sec
type: long
description: >
Uptime of Traefik instance in seconds
- name: response
type: group
description: >
Response metrics
fields:
- name: count
type: long
description: >
Number of responses
- name: avg_time.us
type: long
description: >
Average response time in microseconds
- name: status_code
type: object
object_type: long
description: >
Number of responses per status code
18 changes: 18 additions & 0 deletions metricbeat/module/traefik/health/_meta/test/simple.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"pid": 1,
"uptime": "17h51m23.252891567s",
"uptime_sec": 64283.252891567,
"time": "2018-06-27 22:07:28.966768969 +0000 UTC m=+64283.314491879",
"unixtime": 1530137248,
"status_code_count": {},
"total_status_code_count": {
"200": 17,
"404": 1
},
"count": 0,
"total_count": 18,
"total_response_time": "272.119µs",
"total_response_time_sec": 0.000272119,
"average_response_time": "15.117µs",
"average_response_time_sec": 1.5117e-05
}
Loading