![](/img/trans.png)
[英]python prometheus_client guage metrics are not saved in prometheus
[英]Prometheus Python client library
我開始使用 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 到底要從我的服務監控哪些功能?
您應該將示例中的Summary
等指標添加到您自己的代碼中,它們將在端口 8000 上公開。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.