diff --git a/apache/datadog_checks/apache/__init__.py b/apache/datadog_checks/apache/__init__.py index 8a51d27bc322c..3b8521eda3b9b 100644 --- a/apache/datadog_checks/apache/__init__.py +++ b/apache/datadog_checks/apache/__init__.py @@ -4,7 +4,4 @@ from .__about__ import __version__ from .apache import Apache -__all__ = [ - '__version__', - 'Apache' -] +__all__ = ['__version__', 'Apache'] diff --git a/apache/datadog_checks/apache/apache.py b/apache/datadog_checks/apache/apache.py index c5d944b3e685d..b076b81a97be9 100644 --- a/apache/datadog_checks/apache/apache.py +++ b/apache/datadog_checks/apache/apache.py @@ -1,11 +1,11 @@ # (C) Datadog, Inc. 2010-2017 # All rights reserved # Licensed under Simplified BSD License (see LICENSE) -from six.moves.urllib.parse import urlparse - import requests +from six.moves.urllib.parse import urlparse from datadog_checks.checks import AgentCheck + # compatability layer try: from config import _is_affirmative @@ -24,6 +24,7 @@ class Apache(AgentCheck): See http://httpd.apache.org/docs/2.2/mod/mod_status.html for more details """ + GAUGES = { 'IdleWorkers': 'apache.performance.idle_workers', 'BusyWorkers': 'apache.performance.busy_workers', @@ -34,13 +35,10 @@ class Apache(AgentCheck): 'ConnsTotal': 'apache.conns_total', 'ConnsAsyncWriting': 'apache.conns_async_writing', 'ConnsAsyncKeepAlive': 'apache.conns_async_keep_alive', - 'ConnsAsyncClosing': 'apache.conns_async_closing' + 'ConnsAsyncClosing': 'apache.conns_async_closing', } - RATES = { - 'Total kBytes': 'apache.net.bytes_per_s', - 'Total Accesses': 'apache.net.request_per_s' - } + RATES = {'Total kBytes': 'apache.net.bytes_per_s', 'Total Accesses': 'apache.net.request_per_s'} def __init__(self, name, init_config, agentConfig, instances=None): AgentCheck.__init__(self, name, init_config, agentConfig, instances) @@ -70,20 +68,24 @@ def check(self, instance): service_check_name = 'apache.can_connect' service_check_tags = ['host:%s' % apache_host, 'port:%s' % apache_port] + tags try: - self.log.debug('apache check initiating request, connect timeout %d receive %d' % - (connect_timeout, receive_timeout)) - r = requests.get(url, auth=auth, headers=headers(self.agentConfig), - verify=not disable_ssl_validation, timeout=(connect_timeout, receive_timeout)) + self.log.debug( + 'apache check initiating request, connect timeout %d receive %d' % (connect_timeout, receive_timeout) + ) + r = requests.get( + url, + auth=auth, + headers=headers(self.agentConfig), + verify=not disable_ssl_validation, + timeout=(connect_timeout, receive_timeout), + ) r.raise_for_status() except Exception as e: self.log.warning("Caught exception %s" % str(e)) - self.service_check(service_check_name, AgentCheck.CRITICAL, - tags=service_check_tags) + self.service_check(service_check_name, AgentCheck.CRITICAL, tags=service_check_tags) raise else: - self.service_check(service_check_name, AgentCheck.OK, - tags=service_check_tags) + self.service_check(service_check_name, AgentCheck.OK, tags=service_check_tags) self.log.debug("apache check succeeded") metric_count = 0 # Loop through and extract the numerical values @@ -118,7 +120,7 @@ def check(self, instance): self.warning("Assuming url was not correct. Trying to add ?auto suffix to the url") self.check(instance) else: - raise Exception(( - "No metrics were fetched for this instance. " - "Make sure that %s is the proper url.") - % instance['apache_status_url']) + raise Exception( + ("No metrics were fetched for this instance. Make sure that %s is the proper url.") + % instance['apache_status_url'] + ) diff --git a/apache/setup.py b/apache/setup.py index fe510252f1cbc..5726d3f3049d0 100644 --- a/apache/setup.py +++ b/apache/setup.py @@ -2,12 +2,13 @@ # All rights reserved # Licensed under a 3-clause BSD style license (see LICENSE) -# Always prefer setuptools over distutils -from setuptools import setup # To use a consistent encoding from codecs import open from os import path +# Always prefer setuptools over distutils +from setuptools import setup + HERE = path.abspath(path.dirname(__file__)) @@ -42,17 +43,13 @@ def read(*parts): long_description=long_description, long_description_content_type='text/markdown', keywords='datadog agent apache check', - # The project's main homepage. url='https://github.com/DataDog/integrations-core', - # Author details author='Datadog', author_email='packages@datadoghq.com', - # License license='BSD', - # See https://pypi.python.org/pypi?%3Aaction=list_classifiers classifiers=[ 'Development Status :: 5 - Production/Stable', @@ -63,13 +60,10 @@ def read(*parts): 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', ], - # The package we're going to ship packages=['datadog_checks.apache'], - # Run-time dependencies install_requires=[CHECKS_BASE_REQ], - # Extra files to ship with the wheel package include_package_data=True, ) diff --git a/apache/tests/common.py b/apache/tests/common.py index 380674985b144..a398006f55898 100644 --- a/apache/tests/common.py +++ b/apache/tests/common.py @@ -13,19 +13,11 @@ STATUS_URL = "{0}/server-status".format(BASE_URL) AUTO_STATUS_URL = "{0}?auto".format(STATUS_URL) -STATUS_CONFIG = { - 'apache_status_url': STATUS_URL, - 'tags': ['instance:first'] -} +STATUS_CONFIG = {'apache_status_url': STATUS_URL, 'tags': ['instance:first']} -AUTO_CONFIG = { - 'apache_status_url': AUTO_STATUS_URL, - 'tags': ['instance:second'] -} +AUTO_CONFIG = {'apache_status_url': AUTO_STATUS_URL, 'tags': ['instance:second']} -BAD_CONFIG = { - 'apache_status_url': 'http://localhost:1234/server-status', -} +BAD_CONFIG = {'apache_status_url': 'http://localhost:1234/server-status'} APACHE_GAUGES = [ 'apache.performance.idle_workers', @@ -37,10 +29,7 @@ 'apache.conns_total', 'apache.conns_async_writing', 'apache.conns_async_keep_alive', - 'apache.conns_async_closing' + 'apache.conns_async_closing', ] -APACHE_RATES = [ - 'apache.net.bytes_per_s', - 'apache.net.request_per_s' -] +APACHE_RATES = ['apache.net.bytes_per_s', 'apache.net.request_per_s'] diff --git a/apache/tests/conftest.py b/apache/tests/conftest.py index 54ab09bcd7f1a..95c1a4d334be3 100644 --- a/apache/tests/conftest.py +++ b/apache/tests/conftest.py @@ -11,9 +11,7 @@ from datadog_checks.dev import docker_run from datadog_checks.dev.conditions import CheckEndpoints -from .common import ( - HERE, STATUS_URL, STATUS_CONFIG, BASE_URL, CHECK_NAME -) +from .common import BASE_URL, CHECK_NAME, HERE, STATUS_CONFIG, STATUS_URL @pytest.fixture(scope="session") @@ -25,11 +23,8 @@ def dd_environment(): with docker_run( compose_file=os.path.join(HERE, 'compose', 'apache.yaml'), env_vars=env, - conditions=[ - CheckEndpoints([STATUS_URL]), - generate_metrics, - ], - sleep=20 + conditions=[CheckEndpoints([STATUS_URL]), generate_metrics], + sleep=20, ): yield STATUS_CONFIG diff --git a/apache/tests/test_apache.py b/apache/tests/test_apache.py index 49a2224e6b714..645a85988eada 100644 --- a/apache/tests/test_apache.py +++ b/apache/tests/test_apache.py @@ -6,9 +6,7 @@ from datadog_checks.apache import Apache -from .common import ( - BAD_CONFIG, STATUS_CONFIG, APACHE_GAUGES, APACHE_RATES, HOST, PORT, AUTO_CONFIG -) +from .common import APACHE_GAUGES, APACHE_RATES, AUTO_CONFIG, BAD_CONFIG, HOST, PORT, STATUS_CONFIG @pytest.mark.usefixtures("dd_environment") diff --git a/apache/tox.ini b/apache/tox.ini index dd9ae83367d7f..86ac2ab91a25c 100644 --- a/apache/tox.ini +++ b/apache/tox.ini @@ -7,6 +7,7 @@ envlist = [testenv] usedevelop = true +dd_check_style = true platform = linux|darwin|win32 deps = -e../datadog_checks_base[deps]