prometheus / node_exporter

Exporter for machine metrics

Home Page:https://prometheus.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

json: cannot unmarshal array into Go struct field .labels of type model.LabelValue

ghubz opened this issue · comments

commented

Hi,

I have Prometheus scraping from a json file which is updated via a cronjob.

All was fine until we change the json structure to be from

{
        "targets": [
            "1.2.3.4:9100"
        ],
        "labels": {
            "server_id": "xxxx",
            "server_ip": "1.2.3.4",
            "label": "WINDOWS-SERVER",
            "server_hostname": "WINDOWS-SERVER-LONDON",
            "server_tags": "version:22,edition:ent,admin:john,setup:2023"
        }
 }

to:

{
        "targets": [
            "1.2.3.4:9100"
        ],
        "labels": {
            "server_id": "xxxx",
            "server_ip": "1.2.3.4",
            "label": "WINDOWS-SERVER",
            "server_hostname": "WINDOWS-SERVER-LONDON",
            "server_tags": [
                "version:22",
                "edition:ent",
                "admin:john",
                "setup:2023"
            ]
        }
  }

so the tags are now in an array instead of a string.

This produces the following error:
err="json: cannot unmarshal array into Go struct field .labels of type model.LabelValue"

Is there any solution?

Prometheus 2.46.0
go1.20.6

commented

As the json is created from a third party app which returns the data in an array, I ended up using jq to join the array into a string as it was before. You may ignore the issue.

Doesn't seem node-exporter specific.

For questions/help/support please use our community channels. There are more people available to potentially respond to your request and the whole community can benefit from the answers provided.