Skip to content
This repository has been archived by the owner on Aug 11, 2023. It is now read-only.

add sentry (raven) #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.5-slim
FROM python:3.6-slim
MAINTAINER The MyBook Developers <dev@mybook.ru>

RUN groupadd zabbix_exporter && useradd --no-create-home --gid zabbix_exporter zabbix_exporter
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
history = history_file.read()

requirements = [
'prometheus-client>=0.0.13',
'prometheus-client==0.1.0',
Copy link
Member Author

Choose a reason for hiding this comment

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

pin to avoid non-trivial upgrade just now

'pyzabbix>=0.7.4',
'PyYAML>=3.11',
'click>=6.4',
'raven>=6.9.0',
]

test_requirements = [
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py27, py35, py36, pypy
envlist = py35, py36
skipsdist = true

[testenv]
Expand Down
11 changes: 10 additions & 1 deletion zabbix_exporter/commands.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion zabbix_exporter/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down