json_exporter icon indicating copy to clipboard operation
json_exporter copied to clipboard

check if string value is 'UP'

Open vasylherman opened this issue 2 years ago • 5 comments

hello, I have a response from my server like that"

{
    "status": "UP|DOWN"
}

Is there a way to build a `service_status out of it?

metrics:
  - name: service_status
    path: "{ ?(@.status=='UP') }"

This did not work. Appreciate your help. Thanks!

vasylherman avatar May 06 '22 12:05 vasylherman

    metrics:
      - name: health
        type: object
        path: '@.status == "UP"'
        help: Health Check Status
        values:
          active: 1

works for me^(TM)

weigo avatar Aug 19 '22 14:08 weigo

This might work for you in case you have more enumerations (not just UP and DOWN) - https://github.com/prometheus-community/json_exporter/issues/186#issuecomment-1328156005

rustycl0ck avatar Nov 30 '22 10:11 rustycl0ck

  metrics:
  - name: service
    path: '{ .status }'
    type: object
    help: Health Check Status
    labels:
      status: '{}'
    values:
      health: 1

@PrettySolution This might work for you.....XD @rustycl0ck

ScroogeZhang avatar Feb 14 '23 13:02 ScroogeZhang

  metrics:
  - name: service
    path: '{ .status }'
    type: object
    help: Health Check Status
    labels:
      status: '{}'
    values:
      health: 1

@PrettySolution This might work for you.....XD @rustycl0ck

it doesn't work for me.I got an Error when status goes from UP to DOWN

qq1012827513 avatar May 12 '23 02:05 qq1012827513

I have a similar issue. The suggestion above works, but it only shows metrics for items in the UP state. Is there a way to also return metrics for DOWN items with a value of 0? Example JSON:

{
    "response": [
        {
            "id": 0,
            "Name": "DM Out 1",
            "VideoStatus": "No Sync"
        },
        {
            "id": 2,
            "Name": "SDI 8K quad",
            "VideoStatus": "Mismatch Format"
        },
        {
            "id": 3,
            "Name": "Kumo Out 4 single",
            "VideoStatus": "Valid"
        }
    ]
}

My config:

metrics:
  - name: e2_input
    type: object
    path: '{.result.response[?(@.VideoStatus == "Valid")]}'
    labels:
      name: '{.Name}'
      id: '{.id}'
    values:
      valid: 1

The result is just one metric

e2_input_valid{id="3",name="Kumo Out 4 single"} 1

I would like to have 3 metrics with the ID number appended to the name like this:

e2_input0_valid{name="DM Out 1"} 0
e2_input2_valid{name="DI 8K quad"} 0
e2_input3_valid{name="Kumo Out 4 single"} 1

llamafilm avatar Nov 28 '23 06:11 llamafilm