在 IPv6 上使用 Prometheus 的 Python 客户端

问题描述 投票:0回答:1

我正在使用 Prometheus 的官方 Python 客户端为我的应用程序编写一个自定义导出器 我的代码与下面的代码片段配合得很好(我正在编辑其余的代码,因为我认为这与我要解决的问题无关)面向。)

from prometheus_client import start_http_server, Gauge
start_http_server(9669)

如果我这样做,我就能得到回复

curl --noproxy "*" -v http://localhost:9669/metrics

来自同一台机器。这里的问题是我的 IPv6 服务器。因此,无法从运行 Prometheus 的服务器访问此端点。怎样才能做到

start_http_server

在 IPv6 上还是有解决方法?

我尝试运行一个 Flask 应用程序并在安装了 Prometheus 的机器上执行curl 操作。我没有得到回复

from flask import Flask

app = Flask(__name__)

@app.route('/hello')
def hello_world():
    return 'Hello, World!'

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8989) 

但是如果我将该行修改为

我会得到响应
app.run(host='::', port=8989)

所以我想我需要运行 Prometheus

start_http_server

在 IPv6 上。我试过了

start_http_server(9669, addr='[::]')

但我收到错误

socket.gaierror: [Errno -2] Name or service not known

并且为了

start_http_server(9669, addr='::')

我收到错误

socket.gaierror: [Errno -9] Address family for hostname not supported
python prometheus ipv6 ipv4 prometheus-python-client
1个回答
0
投票

您可能使用的是旧版本的 Python Prometheus 客户端。

我尝试了使用 Python 3.8 的最新版本 0.19.0,这段代码对我来说工作得很好(服务器侦听 IPv6):

from prometheus_client import start_http_server

if __name__ == '__main__':
    start_http_server(9999, addr='::')
    while True:
        pass

根据 Google 搜索,您的错误(“不支持主机名的地址系列”)已报告于here,已修复在此 PR 中,然后从 2022 年 4 月起在 0.14.0 中发布。

© www.soinside.com 2019 - 2024. All rights reserved.