【问题标题】:Prometheus Python client libraryPrometheus Python 客户端库
【发布时间】:2017-06-27 19:26:15
【问题描述】:

我开始使用 Prometheus 来获取有关我已构建的服务的趋势数据。我正在尝试使用 Python 客户端库,但我不清楚如何使用它。

根据“入门”文档,有一个 prometheus.yml 文件指向您要监控的应用程序,Python 客户端库有此代码作为示例。

from prometheus_client import start_http_server, Summary
import random
import time

# Create a metric to track time spent and requests made.
REQUEST_TIME = Summary('request_processing_seconds', 'Time spent processing request')

# Decorate function with metric.
@REQUEST_TIME.time()
def process_request(t):
    """A dummy function that takes some time."""
    time.sleep(t)

if __name__ == '__main__':
    # Start up the server to expose the metrics.
    start_http_server(8000)
    # Generate some requests.
    while True:
        process_request(random.random())

看起来它启动了自己的服务器,并不意味着与我的服务中的代码交织在一起。

所以我的问题是,我如何使用 Prometheus 客户端来告诉 Prometheus 确切地从我的服务中监控哪些功能?

【问题讨论】:

    标签: python monitoring prometheus


    【解决方案1】:

    您应该将示例中的 Summary 等指标添加到您自己的代码中,它们将在端口 8000 上公开。

    【讨论】:

    • 那么我是否将prometheus_client 导入到我要监控的代码中?还是作为单独的服务存在?
    • 是的,将其导入您要检测的每个文件中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-10
    • 1970-01-01
    • 1970-01-01
    • 2010-12-05
    • 1970-01-01
    • 1970-01-01
    • 2018-06-03
    相关资源
    最近更新 更多