json_exporter icon indicating copy to clipboard operation
json_exporter copied to clipboard

Parsing json-object with dot in their name?

Open jounivarjonen opened this issue 3 years ago • 2 comments

Hi, I've been trying but not succeeding to parse json data as follows:

{
  "version" : "4.0.0",
  "gauges" : { },
  "counters" : {
    "TransferManager.downloads.queue" : {
      "count" : 2
    },
    "TransferManager.forwards.queue" : {
      "count" : 0
    },
    "TransferManager.transfers.active" : {
      "count" : 5
    }
  },
  "histograms" : { },
  "meters" : 
    {
    "TransferManager.downloads.failed" : {
      "count" : 1012,
      "m15_rate" : 0.0031013012486067124,
      "m1_rate" : 0.020422990475295447,
      "m5_rate" : 0.008097230208595894,
      "mean_rate" : 0.0013440113841602863,
      "units" : "events/second"
    },
    "TransferManager.downloads.succeeded" : {
      "count" : 20407,
      "m15_rate" : 0.02925335031554721,
      "m1_rate" : 0.019210550446002225,
      "m5_rate" : 0.025774833786456255,
      "mean_rate" : 0.027102016120216895,
      "units" : "events/second"
    },
    "TransferManager.forwards.failed" : {

Didn't paste the whole json but the idea is that I would like to parse that data from the endpoint without modifying it. I got this working by changing all dots to _

My config before changing the JSON:

---
modules:
  default:
    metrics:
    - name: execution_status
      type: object
      path: '$.meters["TransferManager.downloads.failed"]'
      labels:
        count: '.count'
      values:
        status: 1`

This didn't work. It says that Transfer Manager cannot be found.

This works after changing the data:

---
modules:
  default:
    metrics:

    - name: Failed_Downloads
      type: object
      help: Metrics for Failed Downloads 
      path: "{.meters.TransferManager_downloads_failed}"
      labels:
        environment: xxxxxx
        metrics: transfer statistics
        system: xxxxxxx
        owner: xxxx
        count: '{.count}'
      values:
        status: '{.count}'

I would love to get things parsed without first fetching the JSON and then modifying and after that serving modified data from localhost to the scraper.

Probably it's just me that doesn't understand but wanted to ask you guys.

Delete this is just me being stupid.

Cheers

jounivarjonen avatar Jan 31 '23 12:01 jounivarjonen

I guess this might be helpful for you https://github.com/prometheus-community/json_exporter/issues/126#issuecomment-1058337924

dk-seo avatar May 10 '23 18:05 dk-seo

this is an open bug in client-go/jsonpath() https://github.com/kubernetes/client-go/issues/1018

thst-nordic avatar Aug 28 '23 14:08 thst-nordic