显示Grafana中指标的最新值

时间:2019-10-14 05:16:03

标签: grafana

我对Grafana并不陌生,我正在尝试创建一个面板,该面板提供每个组件的软件的最新版本。我的数据源是普罗米修斯。下面是Grafana中的查询检查器。问题是value属性在version字段(即1.4.3)中时,metric始终为1。理想情况下,该表将显示jobpodserviceversion

{
  "xhrStatus": "complete",
  "request": {
    "method": "GET",
    "url": "api/datasources/proxy/4/api/v1/query_range?query=fabric_version&start=1570982400&end=1571025600&step=43200&timeout=60s"
  },
  "response": {
    "status": "success",
    "data": {
      "resultType": "matrix",
      "result": [
        {
          "metric": {
            "endpoint": "https",
            "instance": "10.129.0.13:8443",
            "job": "ibp-os-metrics",
            "namespace": "ibp",
            "pod": "oskrgfu1-7bf78b7ff8-99ktp",
            "service": "ibp-os-metrics",
            "version": "1.4.3"
          },
          "values": [
            [
              1570982400,
              "1"
            ],
            [
              1571025600,
              "1"
            ]
          ]
        },
        {
          "metric": {
            "endpoint": "https",
            "instance": "10.129.0.14:8443",
            "job": "ibp-os-metrics",
            "namespace": "ibp",
            "pod": "oskrgfu3-758874c4dd-xg672",
            "service": "ibp-os-metrics",
            "version": "1.4.3"
          },
          "values": [
            [
              1570982400,
              "1"
            ],
            [
              1571025600,
              "1"
            ]
          ]
        },
        {
          "metric": {
            "endpoint": "https",
            "instance": "10.129.0.15:9443",
            "job": "ibp-org1-metrics",
            "namespace": "ibp",
            "pod": "org1peer1-5794969465-zbfrq",
            "service": "ibp-org1-metrics",
            "version": "1.4.3"
          },
          "values": [
            [
              1570982400,
              "1"
            ],
            [
              1571025600,
              "1"
            ]
          ]
        },
        {
          "metric": {
            "endpoint": "https",
            "instance": "10.130.0.17:8443",
            "job": "ibp-os-metrics",
            "namespace": "ibp",
            "pod": "oskrgfu4-7d7fb7f8d9-hhm4r",
            "service": "ibp-os-metrics",
            "version": "1.4.3"
          },
          "values": [
            [
              1570982400,
              "1"
            ],
            [
              1571025600,
              "1"
            ]
          ]
        },
        {
          "metric": {
            "endpoint": "https",
            "instance": "10.130.0.19:9443",
            "job": "ibp-org1-metrics",
            "namespace": "ibp",
            "pod": "org1peer2-66d6dc8b97-wvxbm",
            "service": "ibp-org1-metrics",
            "version": "1.4.3"
          },
          "values": [
            [
              1570982400,
              "1"
            ],
            [
              1571025600,
              "1"
            ]
          ]
        },
        {
          "metric": {
            "endpoint": "https",
            "instance": "10.131.0.13:8443",
            "job": "ibp-os-metrics",
            "namespace": "ibp",
            "pod": "oskrgfu2-5fc85bfb46-2sfv9",
            "service": "ibp-os-metrics",
            "version": "1.4.3"
          },
          "values": [
            [
              1570982400,
              "1"
            ],
            [
              1571025600,
              "1"
            ]
          ]
        },
        {
          "metric": {
            "endpoint": "https",
            "instance": "10.131.0.15:8443",
            "job": "ibp-os-metrics",
            "namespace": "ibp",
            "pod": "oskrgfu5-b68d5bd7b-564g7",
            "service": "ibp-os-metrics",
            "version": "1.4.3"
          },
          "values": [
            [
              1570982400,
              "1"
            ],
            [
              1571025600,
              "1"
            ]
          ]
        }
      ]
    }
  }
}

我可以使用fabric-version查询,但是不能自定义表格列

enter image description here

1 个答案:

答案 0 :(得分:1)

"version": "1.4.3"是指标的标签,即指标1中的值。指标值存储在"values":[]数组中。此指标可以显示为:

fabric_version{...,version="1.4.3"}   1

如何解决它:

  • 查询提及版本:
    • 查询:fabric_version{version="1.4.3"}
    • 您将获得版本1.4.3的Pod列表
    • 对其他版本也是如此
  • 从代码更改指标定义
    • fabric_version声明为gauge
    • 在导出前设置版本值1.4.3或其他内容
    • 您将获得等于版本而不是1的值