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时,已经注册了度量标准。不知何故,这些指标并没有保存在普罗米修斯中。每当我在grafana中停止python脚本时,我就无法查看数据,Prometheus tsdb中也没有任何历史数据可用于查看Prometheus web URL
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池数据收集器的prometheus.yml
- job_name: 'python-exporter
scrape_interval: 5s
static_configs:
- targets: ['hostname:1234']只有在使用python脚本时才能查看数据;稍后,该数据不会保存在Prometheus中。我没有使用任何自定义注册表,如何使用/metrics将已注册数据保存到使用prometheus_client的Prometheus?我已经更改了普罗米修斯tsdb的保留期。
发布于 2022-09-14 08:20:49
数据保存到普罗米修斯;下面的链接有更多信息
https://github.com/prometheus/client_python/discussions/837
我使用pool_details{name=~"testing-pool-purpose"}[30d]在Prometheus浏览器上查看了最后30天的数据,我确实看到数据保存到Prometheus;在grafana中没有显示信息的原因是我使用了速率查询和instant on grafana表选项,后者只显示了最新的时间戳。当我关闭instant时,我可以看到grafana中的数据;我需要更好地构造查询以获得grafana中的数据。
https://stackoverflow.com/questions/73626503
复制相似问题