[通过Pushgateway暴露具有多个度量的普罗米修斯量规会引发错误,“ Gauge”对象没有属性'_value'。一旦抛出错误的行被注释掉,push_to_gateway()就会抛出
urlopen error [WinError 10061] No connection could be made because the target machine actively refused it
[尝试输入http://localhost:9091/时没有任何响应。
我试图通过HTTP客户端通过标准方法公开指标。但是,python代码只能按需运行并带有参数。它将运行几秒钟并退出。我决定尝试使用Pushgateway。我试图按照https://github.com/prometheus/client_python#exporting-to-a-pushgateway中的指南进行操作。我在本地安装了prometheus,并在编辑yaml文件后通过将scrape config替换为:>
scrape_configs: - job_name: pushgateway honor_labels: true static_configs: - targets: - localhost:9091
实际代码:
# ( Class attribute ) iv_registry = CollectorRegistry() # Gauge to be passed to the Prometheus iv_gauge = Gauge(ic_gauge_name, ic_gauge_docu_labels, ic_labels_list, registry=iv_registry) def __create_gauge(self): """Fill gauge to be passed to the prometheus and graffana""" try: # Set labels and assign a metric self.iv_gauge.labels( label1 = "AAA", label2 = "BBB", label3 = "CCC" ).set(4) self.iv_gauge.labels( label1 = "AAA", label2 = "BBB", label3 = "DDD" ).set(0) # expose in a batch mode self.iv_gauge.set_to_current_time() # Does it have to be here? My gauge itself does not have any _value, on matrics with labels store _values push_to_gateway('localhost:9091', job='batchA', registry=self.iv_registry)
我希望看到一个由Prometheus抓取并已推送到Pushgateway的具有不同度量标准的度量标准,并用于本地测试,从而能够像通过HTTP服务器公开http://localhost:8000/一样在localhost上显示该度量标准。请在下面找到示例。
TYPE gauge_name gauge
gauge_name{label1="AAA",label2="BBB",label3="CCC"} 4.0
gauge_name{label1="AAA",label2="BBB",label3="DDD"} 0.0
[通过Pushgateway暴露具有多个度量的普罗米修斯量规会引发错误,“ Gauge”对象没有属性'_value'。注释行引发错误后,push_to_gateway()引发...
将以下内容粘贴到Python解释器中: