简体   繁体   English

python prometheus_client guage 指标未保存在 prometheus 中

[英]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


I can see metrics are registered when I curl -K http://localhost:1234.当我 curl -K http://localhost:1234 时,我可以看到指标已注册。 Somehow the metrics are not saved in the Prometheus.不知何故,指标没有保存在 Prometheus 中。 I can't view the data whenever I stop the python script in grafana, and there is no historical data held in the Prometheus tsdb to view on the Prometheus web URL每当我在 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

Here is my prometheus.yml for custom python Prometheus collector for pool data这是我的prometheus.yml用于自定义 python 用于池数据的 Prometheus 收集器

  - job_name: 'python-exporter
    scrape_interval: 5s
    static_configs:
      - targets: ['hostname:1234']

I can view the data only when I use the python script;只有使用 python 脚本时才能查看数据; later, that data is not saved in Prometheus.后来,该数据没有保存在 Prometheus 中。 I'm not using any custom registry, How to save registered data in /metrics to Prometheus using prometheus_client?我没有使用任何自定义注册表,如何使用 prometheus_client 将 /metrics 中的注册数据保存到 Prometheus? I already changed my retention period of Prometheus tsdb我已经更改了 Prometheus tsdb 的保留期

The data was saved to Prometheus, following link have more info数据已保存到 Prometheus,以下链接有更多信息

https://github.com/prometheus/client_python/discussions/837 https://github.com/prometheus/client_python/discussions/837

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM