【问题标题】:Send custom data to Prometheus向 Prometheus 发送自定义数据
【发布时间】:2019-10-28 13:58:46
【问题描述】:

我是 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

我已开始为 Prometheus 服务。

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

【问题讨论】:

    标签: python prometheus


    【解决方案1】:

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

    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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-09
      • 1970-01-01
      • 1970-01-01
      • 2017-08-19
      • 1970-01-01
      相关资源
      最近更新 更多