From 7ca08b12c0bcb1d69d0b04e4201f813b85dc75d0 Mon Sep 17 00:00:00 2001 From: genofire Date: Tue, 9 Jun 2020 20:56:01 +0200 Subject: [PATCH] fix ipv6 support for prometheus --- prometheus.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/prometheus.py b/prometheus.py index 9e45d69..007b4f6 100755 --- a/prometheus.py +++ b/prometheus.py @@ -6,6 +6,7 @@ import logging from time import time from collections import defaultdict from http.server import BaseHTTPRequestHandler, HTTPServer +from socket import AF_INET6 from urllib.parse import parse_qs, urlparse from prometheus_client import ( CollectorRegistry, Gauge, generate_latest, CONTENT_TYPE_LATEST @@ -96,6 +97,8 @@ class Prometheus(): return registry 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.serve_forever()