aldred
aldred

Reputation: 853

Display latest value of a metric in Grafana

I am very new to Grafana and I am trying to create a panel which gives the latest version of a software of each component. My data source is Prometheus. The query inspector in Grafana is attached below. The issue is the value is always 1 while the version property is in the metric field (i.e. 1.4.3). Ideally it will be table that shows the job, pod and service and version

{
  "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"
            ]
          ]
        }
      ]
    }
  }
}

I can use fabric-version query but I cannot customize the table columns

enter image description here

Upvotes: 0

Views: 4778

Answers (1)

Kamol Hasan
Kamol Hasan

Reputation: 13476

"version": "1.4.3" is a label of your metrics, the value of the metrics in 1. values of metrics are stored in "values":[] array. This metric can be shown as:

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

How you can fix it:

  • Query mentioning version:
    • query: fabric_version{version="1.4.3"}
    • you will get the list of pods with version 1.4.3
    • do same for other versions too
  • Change metric definition from code
    • declare fabric_version as gauge
    • set version value 1.4.3 or whatever before exporting
    • you will get value equal to version instead of 1

Upvotes: 1

Related Questions