json_exporter
json_exporter copied to clipboard
check if string value is 'UP'
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!
metrics:
- name: health
type: object
path: '@.status == "UP"'
help: Health Check Status
values:
active: 1
works for me^(TM)
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
metrics:
- name: service
path: '{ .status }'
type: object
help: Health Check Status
labels:
status: '{}'
values:
health: 1
@PrettySolution This might work for you.....XD @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
it doesn't work for me.I got an Error when status goes from UP to DOWN
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