prometheus-community / json_exporter

A prometheus exporter which scrapes remote JSON by JSONPath
Apache License 2.0
638 stars 197 forks source link

Having trouble with jsonpath syntax scraping and array of objects #328

Open mbaddah opened 2 months ago

mbaddah commented 2 months ago

I can scrape a single object from the following data kyoto-dst.json using configuration like this:

modules:
  kyoto_dst:
    metrics:
      - name: kyoto_dst_value
        path: '{ [1][1] }'
        help: "Kyoto Dst Index value"
        labels:
          time_tag: '{ [1][0] }'
        metrics:
      - name: kyoto_dst_value_01
        path: '{ [2][1] }'
        help: "Kyoto Dst Index value"
        labels:
          time_tag: '{ [2][0] }'
      - name: kyoto_dst_value_02
        path: '{ [3][1] }'
        help: "Kyoto Dst Index value"

However if i try to use a range to iterate over the entire set I run into all sorts of issues :( I've tried a whole range of configuration settings such as the following:

  kyoto_dst:
    metrics:
      - name: kyoto_dst_value
        path: '{range .[*]}{.[1]}{end}'
        help: "Kyoto Dst Index value"
        labels:
          time_tag: '{.[0]}'
modules:
  kyoto_dst:
    metrics:
      - name: kyoto_dst_value
        path: '[*][1]'
        help: "Kyoto Dst Index value"
        labels:
          time_tag: '[*][0]'

etc...

Would appreciate if anyone can guy me as to what i'm doing wrong, or whether this is even supported in json exporter? The original link can be found here https://services.swpc.noaa.gov/products/kyoto-dst.json , thanks!