-
Notifications
You must be signed in to change notification settings - Fork 765
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Init Datadog integrations for Traefik.
- Loading branch information
Renaud HAGER
committed
Jul 21, 2018
1 parent
3de28b1
commit 0f9e835
Showing
27 changed files
with
457 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[flake8] | ||
ignore = W292,E226,E501,F401,E303 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# CHANGELOG - traefik | ||
|
||
## 0.1.0 | ||
|
||
* [FEATURE] first version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
include README.md | ||
include requirements.in | ||
include requirements.txt | ||
include requirements-dev.txt | ||
graft datadog_checks | ||
graft tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# traefik Integration | ||
|
||
## Overview | ||
|
||
This collect for Traefik and check it health. | ||
|
||
## Setup | ||
|
||
### Installation | ||
|
||
[...] | ||
|
||
### Configuration | ||
|
||
Create a `traefik.yaml` in the Datadog Agent's `conf.d` directory. | ||
|
||
#### Metric Collection | ||
|
||
Add this configuration setup to your `traefik.yaml` file to start gathering your [metrics][2]: | ||
|
||
``` | ||
init_config: | ||
instances: | ||
- host: 10.1.1.2 | ||
- port: 8080 | ||
- path: /health | ||
``` | ||
|
||
Configuration Options: | ||
|
||
- host: Traefik endpoint to query. __Required__ | ||
- port: API listener of Traefik endpoint. Default value `8080`. _Optional_ | ||
- path: Path of Traefik health check endpoint. Default `/health`. _Optional_ | ||
|
||
[Restart the Agent][3] to begin sending Traefil metrics to Datadog. | ||
|
||
### Validation | ||
|
||
[Run the Agent's `status` subcommand][4] and look for `traefik` under the Checks section: | ||
|
||
``` | ||
Checks | ||
====== | ||
[...] | ||
traefik | ||
------- | ||
- instance #0 [OK] | ||
- Collected 2 metrics, 0 events & 1 service check | ||
[...] | ||
``` | ||
|
||
## Compatibility | ||
|
||
The check is compatible with all major platforms. | ||
|
||
## Data Collected | ||
|
||
### Metrics | ||
|
||
See [metadata.csv][5] for a list of metrics provided by this integration. | ||
|
||
### Events | ||
|
||
The traefik check does not include any event at this time. | ||
|
||
### Service Checks | ||
|
||
Query Traefik and expect `200` as return status code. | ||
|
||
## Troubleshooting | ||
|
||
[...] | ||
|
||
## Development | ||
|
||
Please refer to the [main documentation][6] | ||
for more details about how to test and develop Agent based integrations. | ||
|
||
[1]: https://raw.githubusercontent.com/DataDog/cookiecutter-datadog-check/master/%7B%7Bcookiecutter.check_name%7D%7D/images/snapshot.png | ||
[2]: #metrics | ||
[3]: https://docs.datadoghq.com/agent/faq/agent-commands/#start-stop-restart-the-agent | ||
[4]: https://docs.datadoghq.com/agent/faq/agent-commands/#agent-status-and-information | ||
[5]: https://github.com/DataDog/cookiecutter-datadog-check/blob/master/%7B%7Bcookiecutter.check_name%7D%7D/metadata.csv | ||
[6]: https://docs.datadoghq.com/developers/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
init_config: | ||
|
||
instances: | ||
- host: 10.1.2.3 | ||
- port: 8080 | ||
- path: health |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# (C) Datadog, Inc. 2018 | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) | ||
|
||
__path__ = __import__('pkgutil').extend_path(__path__, __name__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# (C) Datadog, Inc. 2018 | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) | ||
|
||
__version__ = '0.1.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# (C) Datadog, Inc. 2018 | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) | ||
|
||
from .traefik import TraefikCheck | ||
from .__about__ import __version__ | ||
|
||
__all__ = [ | ||
'__version__', | ||
'TraefikCheck' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# (C) Datadog, Inc. 2018 | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) | ||
|
||
import requests | ||
import json | ||
|
||
from datadog_checks.checks import AgentCheck | ||
from datadog_checks.errors import CheckException | ||
|
||
|
||
class TraefikCheck(AgentCheck): | ||
|
||
def check(self, instance): | ||
host = instance.get('host') | ||
port = instance.get('port', '8080') | ||
path = instance.get('path', '/health') | ||
|
||
if not host: | ||
self.warning("Configuration error, please fix traefik.yaml") | ||
raise CheckException("Configuration error, please fix traefik.yaml") | ||
|
||
try: | ||
url = "http://" + host + ":" + port + path | ||
response = requests.get(url) | ||
response_status_code = response.status_code | ||
|
||
if response_status_code == 200: | ||
self.service_check('traefik.health', self.OK, tags=None, message="") | ||
|
||
payload = json.loads(response.text) | ||
|
||
if 'total_status_code_count' in payload: | ||
values = payload['total_status_code_count'] | ||
|
||
for status_code in values: | ||
self.gauge('traefik.total_status_code_count', values[status_code], ['status_code:' + status_code]) | ||
|
||
else: | ||
self.log.warn('Field total_status_code_count not found in response.') | ||
|
||
if 'total_count' in payload: | ||
self.gauge('traefik.total_count', payload['total_count']) | ||
else: | ||
self.log.warn('Field total_count not found in response.') | ||
|
||
else: | ||
self.service_check('traefik.health', self.CRITICAL, tags=None, message="Traefik health check return code is not 200") | ||
|
||
except requests.exceptions.ConnectionError: | ||
self.service_check('traefik.health', self.CRITICAL, tags=None, message="Traefik endpoint unreachable") | ||
|
||
except Exception as e: | ||
self.service_check('traefik.health', self.UNKNOW, tags=None, message="Unknow exception" + str(e)) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"maintainer": "help@datadoghq.com", | ||
"manifest_version": "1.0.0", | ||
"name": "traefik", | ||
"short_description": "collects traefik metrics", | ||
"support": "core", | ||
"supported_os": [ | ||
"linux", | ||
"mac_os", | ||
"windows" | ||
], | ||
"guid": "000-000", | ||
"public_title": "traefik Integration", | ||
"categories":[], | ||
"type":"check", | ||
"doc_link": "", | ||
"aliases":[], | ||
"is_public": true, | ||
"has_logo": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
traefik.total_status_code_count,gauge,,,,total count for each returned status code,,traefik,traefik | ||
traefik.total_count,gauge,,,,count total number of requets,,traefik,traefik |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mock==2.0.0 | ||
pytest |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# | ||
# This file is autogenerated by pip-compile | ||
# To update, run: | ||
# | ||
# pip-compile --generate-hashes --output-file requirements.txt requirements.in | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[ | ||
{ | ||
"agent_version": "5.5.0", | ||
"integration":"traefik", | ||
"groups": ["host", "check", "service", "traefik"], | ||
"check": "traefik.check", | ||
"statuses": ["ok", "critical", "unknow"], | ||
"name": "Health check", | ||
"description": "Returns ok if the Traefik is up, critical when down and unknow when unknow exception occured." | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# (C) Datadog, Inc. 2018 | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) | ||
|
||
from setuptools import setup | ||
from codecs import open | ||
from os import path | ||
|
||
HERE = path.abspath(path.dirname(__file__)) | ||
|
||
# Get version info | ||
ABOUT = {} | ||
with open(path.join(HERE, "datadog_checks", "traefik", "__about__.py")) as f: | ||
exec(f.read(), ABOUT) | ||
|
||
# Get the long description from the README file | ||
with open(path.join(HERE, 'README.md'), encoding='utf-8') as f: | ||
long_description = f.read() | ||
|
||
|
||
# Parse requirements | ||
def get_requirements(fpath): | ||
with open(path.join(HERE, fpath), encoding='utf-8') as f: | ||
return f.readlines() | ||
|
||
|
||
setup( | ||
name='datadog-traefik', | ||
version=ABOUT["__version__"], | ||
description='collects traefik metrics', | ||
long_description=long_description, | ||
keywords='datadog agent check', | ||
url='https://github.com/DataDog/integrations-core', | ||
author='Renaud Hager', | ||
author_email='paas@argos.co.uk', | ||
license='BSD', | ||
|
||
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers | ||
classifiers=[ | ||
'Development Status :: 5 - Production/Stable', | ||
'Intended Audience :: Developers', | ||
'Intended Audience :: System Administrators', | ||
'Topic :: System :: Monitoring', | ||
'License :: OSI Approved :: BSD License', | ||
'Programming Language :: Python :: 2', | ||
'Programming Language :: Python :: 2.7', | ||
], | ||
|
||
packages=['datadog_checks.traefik'], | ||
|
||
# Run-time dependencies | ||
install_requires=get_requirements('requirements.in')+[ | ||
'datadog-checks-base', | ||
], | ||
setup_requires=['pytest-runner', ], | ||
tests_require=get_requirements('requirements-dev.txt'), | ||
|
||
# Extra files to ship with the wheel package | ||
package_data={'datadog_checks.traefik': ['conf.yaml.example']}, | ||
include_package_data=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# (C) Datadog, Inc. 2018 | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# (C) Datadog, Inc. 2018 | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def aggregator(): | ||
from datadog_checks.stubs import aggregator | ||
aggregator.reset() | ||
return aggregator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
version: '3' | ||
services: | ||
traefik: | ||
image: traefik:v1.6 | ||
ports: | ||
- 80:80 | ||
- 8080:8080 | ||
volumes: | ||
- ./traefik.toml:/etc/traefik/traefik.toml:ro |
Oops, something went wrong.