Skip to content

Commit

Permalink
Metricbeat module for Traefik (#7413)
Browse files Browse the repository at this point in the history
Resolves #7412.

This PR adds a Metricbeat module for the [Traefik](https://traefik.io/) reverse proxy/load balancer. In this module, it adds the health metricset, whose data it retrieves from polling the Traefik instance's health HTTP API endpoint.
  • Loading branch information
ycombinator authored and ruflin committed Jul 3, 2018
1 parent ddeec6d commit 4071bc7
Show file tree
Hide file tree
Showing 28 changed files with 718 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,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 @@
{
"@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

0 comments on commit 4071bc7

Please sign in to comment.