Jsonpath for prometheus json exporter

139 views Asked by At

I need to generate metrics for Prometheus based on the service's json response. I installed prometheus-json-exporter, I want to do something like in the example https://github.com/prometheus-community/json_exporter/blob/master/examples/config.yml#L22 so that if the value of the json field is .e2eCheckResult.totalStatus == fail, then set the value of the label totalStatus = 1 in the json-exporter config file I wrote the following:

modules:
  default:
    metrics:
      - name: app_e2eCheckResult_totalStatus
        path: '{ $.values[?(@.e2eCheckResult.totalStatus == "fail")] }'
        help: E2E total status from app
        labels:
          environment: prod
          component: app
          totalStatus: '{ $.e2eCheckResult.totalStatus }'
        values:
          totalStatus: 0
        http_client_config:
          tls_config:
            insecure_skip_verify: true

The service returns json something like this:

{
  "e2eCheckResult": {
    "totalStatus": "fail",
    "totalTime":145,
    "e2EComponents": [
      {...}
    ]
  }
}

At the same time, I get the following in the json exporter log:

level=error msg="Failed to execute jsonpath" err="values is not found" path="{ $.values[?(@.e2eCheckResult.totalStatus == \"fail\")] }" data="{\"e2eCheckResult\":{\"totalStatus\":\"fail\",\"totalTime\":145,\"e2EComponents\":[{...}]}}"

Is it possible to somehow set the value of the metric app_e2eCheckResult_totalStatus == 1 if the service returns the value .e2eCheckResult.totalStatus: "ok" and the value of the metric app_e2eCheckResult_totalStatus == 0 if the service returns the value .e2eCheckResult.totalStatus: "fail" ?

0

There are 0 answers