【发布时间】: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