prometheus-community/json_exporter

how to make filters?

Alex0159 opened this issue · 0 comments

Hello! I get errors with the following configuration
...Failed to execute jsonpath... or ...Failed to extract json objects for metric...

data.json

{
  "status": "UP",
  "components": {
    "SERVICE_1": {
      "status": "UP",
      "details": {
        "name": "This is SERVICE_1",
        "info": {
          "updated": "2024-08-21T14:54:00.019521649",
          "additional_details": {
            "url": "http://localhost/service-1"
          }
        }
      }
    },
    "SERVICE_2": {
      "status": "UP",
      "details": {
        "name": "This is SERVICE_2",
        "info": {
          "updated": "2024-08-21T14:54:00.019521649",
          "additional_details": {
            "url": "http://localhost/service-2"
          }
        }
      }
    },
    "SERVICE_3": {
      "status": "DOWN",
      "details": {
        "name": "This is SERVICE_3",
        "info": {
          "updated": "2024-08-21T14:54:00.019521649",
          "additional_details": {
            "url": "http://localhost/service-3"
          }
        }
      }
    }
  }
}

config.yml:

---
modules:
  default:
    headers:
      X-Dummy: my-test-header
    metrics:

      - name: status
        type: object
        help: 'This is SERVICE_UP'
        path: '{.components..[?(@.status == "UP")]}'
        labels:
          component: '{.components..[?(@.status == "UP")]~}'
        values:
          UP: 1

      - name: status
        type: object
        help: 'This is SERVICE_DOWN'
        path: '{.components..[?(@.status == "DOWN")]}'
        labels:
          component: '{.components..[?(@.status == "DOWN")]~}'
        values:
          DOWN: 0

output expected:

# HELP status_UP This is SERVICE_UP
# TYPE status_UP untyped
status_UP{component="SERVICE_1"} 1
status_UP{component="SERVICE_2"} 1

# HELP status_DOWN This is SERVICE_DOWN
# TYPE status_DOWN untyped
status_DOWN{component="SERVICE_3"} 0