![](/img/trans.png)
[英]Expose package metrics to Prometheus with prometheus_client
[英]python prometheus_client guage metrics are not saved in prometheus
import prometheus_client as prom, Guage
import random
import time
pool={'pool_name': 'testing-prom-tool','member_name': 'promtest', 'mem_port': '443', 'mem_address': 'xx.xx.xx.xx', 'mem_state': 'down'}
# Create a metric to track time spent and requests made.
REQUEST_TIME = prom.Summary('request_processing_seconds', 'Time spent processing request')
# Decorate function with metric.
@REQUEST_TIME.time()
def process_request():
time.sleep(1)
if __name__ == '__main__':
# name documentation label names ### I was able to populate all the keys from the dictionary using the pool. keys())
f5_prom_test = prom.Guage('f5_test','f5_node_status',('pool_name','member_name','mem_port','mem_address','mem_state'))
prom.start_http_server(1234)
While True:
process_request()
f5_prom_test.labels(pool.get('pool_name'),pool.get('member_name'),pool.get('mem_port'),pool.get('mem_address'),pool.get('mem_state'))
#f5_prom.labels(**pool), this works as well
當我 curl -K http://localhost:1234 時,我可以看到指標已注冊。 不知何故,指標沒有保存在 Prometheus 中。 每當我在 grafana 中停止 python 腳本時,我都無法查看數據,並且 Prometheus tsdb 中沒有歷史數據可在 Prometheus web ZE6B391A8D2C4D45902A23A83B 上查看
curl -K http://localhost:1234
f5_test_created{mem_address="xx.xx.xx.xxx",mem_name="test-server",pool_name"=testpool",mem_port="5443",mem_state="down"} 1.658982617711136e+09
這是我的prometheus.yml
用於自定義 python 用於池數據的 Prometheus 收集器
- job_name: 'python-exporter
scrape_interval: 5s
static_configs:
- targets: ['hostname:1234']
只有使用 python 腳本時才能查看數據; 后來,該數據沒有保存在 Prometheus 中。 我沒有使用任何自定義注冊表,如何使用 prometheus_client 將 /metrics 中的注冊數據保存到 Prometheus? 我已經更改了 Prometheus tsdb 的保留期
數據已保存到 Prometheus,以下鏈接有更多信息
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.