diff --git a/Dockerfile b/Dockerfile index ee5c816..740800f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.5-slim +FROM python:3.6-slim MAINTAINER The MyBook Developers RUN groupadd zabbix_exporter && useradd --no-create-home --gid zabbix_exporter zabbix_exporter diff --git a/setup.py b/setup.py index 37ca1ee..df3b6c5 100755 --- a/setup.py +++ b/setup.py @@ -14,10 +14,11 @@ history = history_file.read() requirements = [ - 'prometheus-client>=0.0.13', + 'prometheus-client==0.1.0', 'pyzabbix>=0.7.4', 'PyYAML>=3.11', 'click>=6.4', + 'raven>=6.9.0', ] test_requirements = [ diff --git a/tox.ini b/tox.ini index dc01080..45b1cda 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27, py35, py36, pypy +envlist = py35, py36 skipsdist = true [testenv] diff --git a/zabbix_exporter/commands.py b/zabbix_exporter/commands.py index c120813..38fcec8 100644 --- a/zabbix_exporter/commands.py +++ b/zabbix_exporter/commands.py @@ -1,10 +1,12 @@ # coding: utf-8 import logging +import sys import click -import sys import yaml from prometheus_client import REGISTRY +from raven import Client, setup_logging +from raven.handlers.logging import SentryHandler import zabbix_exporter from zabbix_exporter.core import ZabbixCollector, MetricsHandler @@ -38,6 +40,7 @@ def validate_settings(settings): @click.option('--verbose', is_flag=True) @click.option('--dump-metrics', help='Output all metrics for human to write yaml config', is_flag=True) @click.option('--version', is_flag=True) +@click.option('--sentry', help='Sentry DSN') @click.option('--return-server', is_flag=True, help='Developer flag. Please ignore.') def cli(**settings): """Zabbix metrics exporter for Prometheus @@ -97,6 +100,12 @@ def cli(**settings): if settings['dump_metrics']: return dump_metrics(collector) + if settings['sentry']: + reaven_client = Client(settings['sentry']) + handler = SentryHandler(reaven_client) + handler.setLevel(logging.ERROR) + setup_logging(handler) + REGISTRY.register(collector) httpd = HTTPServer(('', int(settings['port'])), MetricsHandler) click.echo('Exporter for {base_url}, user: {login}, password: ***'.format( diff --git a/zabbix_exporter/core.py b/zabbix_exporter/core.py index 851fdd6..c1a4aef 100644 --- a/zabbix_exporter/core.py +++ b/zabbix_exporter/core.py @@ -147,7 +147,7 @@ def do_GET(self): response = generate_latest(REGISTRY) + generate_latest(exporter_registry) status = 200 except Exception: - logger.exception('Fetch failed') + logger.error('Fetch failed', exc_info=True) response = '' status = 500 self.send_response(status)