当前位置: 首页 > 知识库问答 >
问题:

如何向普罗米修斯推出一个具有多个指标的量表?网关问题

杜霍英
2023-03-14

通过Pushgateway公开具有多个度量的普罗米修斯量表会引发错误“gauge”对象没有属性“\u value”。一旦抛出错误的行被注释,push\u to\u 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-PUSH网关。我在本地安装了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)

我希望看到一个具有不同度量的仪表推送到Pushgateway,由Prometheus刮取并用于本地测试,以便能够在localhost上的某个地方显示它http://localhost:8000/通过HTTP服务器公开。请在下面找到样品。

TYPE gauge_name gauge
gauge_name{label1="AAA",label2="BBB",label3="CCC"} 4.0
gauge_name{label1="AAA",label2="BBB",label3="DDD"} 0.0

共有1个答案

孙夕
2023-03-14

将以下内容粘贴到Python解释器中:

from prometheus_client import CollectorRegistry, Gauge, push_to_gateway

registry = CollectorRegistry()
g = Gauge('job_last_success_unixtime', 'Last time a batch job successfully finished', registry=registry)
g.set_to_current_time()
push_to_gateway('localhost:9091', job='batchA', registry=registry)
 类似资料:
  • 我要监控的应用程序为健康检查提供了一个apiendpoint,该endpoint使用json中的指标进行响应。例如: 我已经设置了Prometheus blackbox\u exporter,以监视此endpoint是否返回200 Ok,但理想情况下,我也希望获得这些指标。我知道instrumentation直接从应用程序导出这些数据。但是,由于应用程序已经在导出json对象中我想要的内容,我更希

  • 我可以在http://localhost:8080/hello/q/metrics看到这个指标。现在我想把这个度量标准推到普罗米修斯,但我还没有找到任何指南,说明如何在普罗米修斯注册/集成这些度量标准。理想情况下,我想把它们推到石墨上,但这不受支持。所以我想知道如何推动这些指标,这样我就可以在格拉法纳可视化它们。

  • 我的各种docker容器导出prometheus度量,但是我们的prometheus安装只需要从一个endpoint提取所有度量。不幸的是,这是无法改变的。因此,我需要在一个点上聚合所有度量,从普罗米修斯安装可以刮取度量。 此外,如果这个程序或脚本能够提供关于如何处理由不同endpoint导出的相同度量的额外逻辑,那就太好了。例如,如果我只是将不同的度量站点连接在一起,Prometheus在解释度

  • 我已经配置了普罗米修斯来获取一些来源的指标。 cadvisor 问题是。 在Prometheus UI中,我可以看到所有的目标,在图形中,我可以查询所有与nodejs相关的指标。但是如果我做,我只看到与普罗米修斯和节点出口商相关的指标。没有任何与nodejs应用程序或hazelcast相关的内容。 直接请求nodejs应用程序毫无问题地返回所有这些值。 什么会导致这样的问题?

  • 我正在使用带Spring靴2的SCDF。x metrics和SCDF metrics collector从我的Spring Boot应用程序收集指标。我真的不理解收集器关于聚合度量(aggregateMetrics)数据的逻辑。 当我获取为我的流收集的指标列表时,我只有以开头的指标,因此我只有平均值。我尝试了所有方法来查看其他指标,就像endpoint公开的指标一样。 我想我误解了指标的聚合方式。

  • 我是从蝗虫出口商那里来的。所以我安装了它,并按照文档中所述的步骤进行操作,然后运行commmand hocust_exporter.py 1234 localhost:8089,其中1234是一个端口。但它也犯了一些错误。 处理来自('127.0.0.1',11950)回溯(最后一次调用)的请求时发生异常:文件“E:\Python\lib\socketserver.py”,第650行,进程中请求线