fix ipv6 support for prometheus

This commit is contained in:
genofire 2020-06-09 20:56:01 +02:00
parent 710e139403
commit 7ca08b12c0
1 changed files with 3 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import logging
from time import time from time import time
from collections import defaultdict from collections import defaultdict
from http.server import BaseHTTPRequestHandler, HTTPServer from http.server import BaseHTTPRequestHandler, HTTPServer
from socket import AF_INET6
from urllib.parse import parse_qs, urlparse from urllib.parse import parse_qs, urlparse
from prometheus_client import ( from prometheus_client import (
CollectorRegistry, Gauge, generate_latest, CONTENT_TYPE_LATEST CollectorRegistry, Gauge, generate_latest, CONTENT_TYPE_LATEST
@ -96,6 +97,8 @@ class Prometheus():
return registry return registry
def listen(self, addr=("127.0.0.1", 8080)): def listen(self, addr=("127.0.0.1", 8080)):
if "::" in addr[0]:
HTTPServer.address_family = AF_INET6
server = HTTPServer(addr, DynamicMetricsHandler.factory(self.handler)) server = HTTPServer(addr, DynamicMetricsHandler.factory(self.handler))
server.serve_forever() server.serve_forever()