Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ipv6 #59

Closed
wants to merge 2 commits into from
Closed

Ipv6 #59

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
12 changes: 8 additions & 4 deletions prometheus_es_exporter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from elasticsearch import Elasticsearch
from elasticsearch.exceptions import ConnectionTimeout
from jog import JogFormatter
from prometheus_client import start_http_server
from prometheus_client.core import GaugeMetricFamily, REGISTRY

from . import cluster_health_parser
Expand All @@ -20,7 +19,7 @@
format_metric_name, merge_metric_dicts)
from .parser import parse_response
from .scheduler import schedule_job
from .utils import log_exceptions, nice_shutdown
from .utils import log_exceptions, nice_shutdown, start_http_server

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -339,6 +338,10 @@ def conv(value):
'Must be specified if "--basic-user" is provided.')
@click.option('--port', '-p', default=9206,
help='Port to serve the metrics endpoint on. (default: 9206)')
@click.option('--ipv6/--ipv4', default=False, is_flag=True,
help='Whether to serve the metrics endpoint on IPv6 or IPv4. '
'Will bind to `::` for IPv6, or `0.0.0.0` for IPv4. '
'(default: IPv4)')
@click.option('--query-disable', default=False, is_flag=True,
help='Disable query monitoring. '
'Config file does not need to be present if query monitoring is disabled.')
Expand Down Expand Up @@ -503,8 +506,9 @@ def cli(**options):
REGISTRY.register(QueryMetricCollector())

log.info('Starting server...')
start_http_server(port)
log.info('Server started on port %(port)s', {'port': port})
start_http_server(port, ipv6=options['ipv6'])
log.info('Server started on %(protocol)s, port %(port)s',
{'port': port, 'protocol': 'IPv6' if options['ipv6'] else 'IPv4'})

if scheduler:
scheduler.run()
Expand Down
12 changes: 12 additions & 0 deletions prometheus_es_exporter/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import functools
import logging
import signal
import socket
import sys

from collections import OrderedDict
from prometheus_client import REGISTRY, start_http_server as orig_start_http_server
from prometheus_client.exposition import _ThreadingSimpleServer

Choose a reason for hiding this comment

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

Suggested change
from prometheus_client.exposition import _ThreadingSimpleServer
from prometheus_client.exposition import ThreadingWSGIServer


log = logging.getLogger(__name__)

Expand Down Expand Up @@ -87,3 +90,12 @@ def wrapper(*args, **kwargs):
return wrapper

return decorator


def start_http_server(port, addr='', registry=REGISTRY, ipv6=False):
# Monkeypatch the server class address family to support IPv6 if needed.
if ipv6:
_ThreadingSimpleServer.address_family = socket.AF_INET6

Choose a reason for hiding this comment

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

Suggested change
_ThreadingSimpleServer.address_family = socket.AF_INET6
ThreadingWSGIServer.address_family = socket.AF_INET6


# Call original start_http_server()
orig_start_http_server(port, addr=addr, registry=registry)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='prometheus-es-exporter',
version='0.8.0.dev1',
version='0.8.0a1',
description='Elasticsearch query Prometheus exporter',
url='https://github.com/braedon/prometheus-es-exporter',
author='Braedon Vickers',
Expand Down