Search code examples
jsonprometheusmetricsexporterprometheus-json-exporter

Failed to execute jsonpath in json_exporter


The goal is this: go to the url with a whip and take information from it, then transfer this information to the alert. So that when a letter arrived that something was broken, it was immediately written what exactly (and what exactly broke was written in the check).

I've got the Healthcheck.:

{
  "status": "OK",
  "description": "All good",
  "sql": null
}

I need to get the description. As a result, I made such a config, focusing on examples:

modules:
  default:
    headers:
      MyHeader: MyHeaderValue
    metrics:
      - name: jsonhc
        type: object
        help: healthcheks description
        path: '{.description}'
        labels:
          env: prod
        values:
          status: 1
          description: '{.description}'

The answer I get is this:

json_exporter | ts=2023-06-22T11:12:38.760Z caller=collector.go:136 level=error msg="Failed to execute jsonpath" err="description is not found" path={.description} data=""All good""

json_exporter | ts=2023-06-22T11:12:38.761Z caller=collector.go:88 level=error msg="Failed to extract value for metric" path={.description} err="description is not found" metric="Desc{fqName: "jsonhc_description", help: "healthcheks description", constLabels: {}, variableLabels: [env]}

The data I get is correct, but I can't take it for an alert. When I check the curl for targets, it's not there.

I ran:

#curl http://localhost:7979/probe

And received:

Target parameter is missing

I've tried different variants of the path variable (such as '$.*' and '{ [*] }') but it doesn't work. Please help me figure it out is this a bug or am I doing something wrong?


Solution

  • So the problem was with Healthcheck itself. This is what it was supposed to be.

    {
      "healthcheck": [
        {
          "status": "OK",
          "description": "All good",
          "sql": null
        }
      ]
    }
    

    After that the module worked as I wanted it to. Also, to do what I had in mind, I needed a module like this.

    path: '{.healthcheck[?(@.status != "OK")]}'
    

    And then in case there was not "OK", I set up an alert so that I would be sent an email when the status == 1