0

I wanted to write a JSON exporter yml config that generate metrics from a URL response when 'Search' keyword present in the 'node_types' string array. (response JSON mentioned below).

Expected Metrics from JSON exporter
search_node_status{environment="dev", app="test-app1"} 1

`{

    "node_type": [
        "Search", 
        "Stream",
        "BackgroundProcessing"
    ],
    "health": [
        {
            "last_reported_time": "2023-02-03T11:05:07.776Z",
            "message": "NORMAL",
            "test_name": "DSMService:DataFlow.Search-Check",
            "status": "success"
        },
        {
            "last_reported_time": "2023-02-03T11:05:07.776Z",
            "test_name": "HTML-Stream-Check",
            "status": "success"
        },
        {
            "last_reported_time": "2023-02-03T11:05:07.776Z",
            "test_name": "Streamservice-Check",
            "status": "success"
        },
        {
            "last_reported_time": "2023-02-03T11:05:07.776Z",
            "message": "NORMAL",
            "test_name": "DSMService:StreamServer.Default-Check",
            "status": "success"
        },
        {
            "last_reported_time": "2023-02-03T11:05:07.776Z",
            "test_name": "ServiceRegistry-Check",
            "status": "success"
        },
        {
            "last_reported_time": "2023-02-03T11:05:07.776Z",
            "test_name": "DataFlowSlowComponentHealthCheck",
            "status": "success"
        },
        {
            "last_reported_time": "2023-02-03T11:05:07.776Z",
            "message": "NORMAL",
            "test_name": "DSMService:DataFlow.BackgroundProcessing-Check",
            "status": "success"
        }
    ],
"state": "healthy",
"node_id": "7ad5634jasdf78ss"

} `

I have tried following config, but its failing with error - Failed to convert extracted value to float64"

PATH key word expect a digit 1 as return value from the expression when "Search" is present in the string array "node_type" and 0 if Search is not present

json_exporter.yml

---
modules:
  default:
    metrics:
    - name: search_node
      path: '{$[?(@.node_type.includes("Search"))].length || 0}'
      labels:
        environment: dev

    headers:
      X-Dummy: my-test-header

Expected Metrics from JSON exporter
search_node_status{environment="dev", app="test-app1"} 1

Vinod
  • 1
  • 1

0 Answers0