将自定义数据发送到 Prometheus

Send custom data to Prometheus

我是 Prometheus 的新手,我想向 Prometheus 发送一些自定义指标。我正在使用这个 client lib.

from prometheus_client import make_wsgi_app
from wsgiref.simple_server import make_server

def prometheus_config():
    app = make_wsgi_app()
    httpd = make_server('', 1618, app)
    httpd.serve_forever()


def start_prometheus_server():
    threading.Thread(target=prometheus_config).start()enter code here

我已经开始为普罗米修斯服务。

  1. 我现在如何启动 /custom 端点?
  2. 我怎样才能把我的寄到那里 自定义数据?

在注册表自定义收集器中注册 class:

class CustomCollector(object):
    def collect(self):
        yield GaugeMetricFamily('my_gauge', 'Help text', value=7)
        c = CounterMetricFamily('my_counter_total', 'Help text', labels=['foo'])
        c.add_metric(['bar'], 1.7)
        c.add_metric(['baz'], 3.8)
        yield c

REGISTRY.register(CustomCollector())

然后在启动服务器时使用这个注册表:

app = make_wsgi_app(REGISTRY)
httpd = make_server('', 1618, app)