英文:
Failed to execute jsonpath in json_exporter
问题
目标是这样的:使用 URL 进行访问,然后从中获取信息,然后将这些信息传递给警报。因此,当有一封信到达指示某些东西坏了时,会立即写明具体是什么(以及在检查中写明了确切是什么坏了)。
我已经获取了 Healthcheck 内容.:
{
"status": "OK",
"description": "All good",
"sql": null
}
我需要获取 description。因此,我创建了这样一个配置,重点是根据示例进行的:
modules:
default:
headers:
MyHeader: MyHeaderValue
metrics:
- name: jsonhc
type: object
help: 健康检查描述
path: '{.description}'
labels:
env: prod
values:
status: 1
description: '{.description}'
我得到的答案是这样的:
> json_exporter | ts=2023-06-22T11:12:38.760Z caller=collector.go:136 level=error msg="执行 jsonpath 失败" err="找不到 description" path={.description} data=""All good""
>
> json_exporter | ts=2023-06-22T11:12:38.761Z caller=collector.go:88 level=error msg="提取指标的值失败" path={.description} err="找不到 description" metric="Desc{fqName: "jsonhc_description", help: "健康检查描述", constLabels: {}, variableLabels: [env]}
我得到的数据是正确的,但我无法将其用于警报。当我检查目标的 curl 时,它不存在。
我运行了:
#curl http://localhost:7979/probe
并收到以下响应:
> 目标参数丢失
我尝试了 path
变量的不同变体(例如 '$.*' 和 '{ [*] }'
)但它不起作用。请帮我弄清楚这是否是一个 bug 还是我做错了什么?
英文:
The goal is this: go to the url with a whip and take information from it, then transfer this information to the alert. So that when a letter arrived that something was broken, it was immediately written what exactly (and what exactly broke was written in the check).
I've got the Healthcheck.:
{
"status": "OK",
"description": "All good",
"sql": null
}
I need to get the description. As a result, I made such a config, focusing on examples:
modules:
default:
headers:
MyHeader: MyHeaderValue
metrics:
- name: jsonhc
type: object
help: healthcheks description
path: '{.description}'
labels:
env: prod
values:
status: 1
description: '{.description}'
The answer I get is this:
> json_exporter | ts=2023-06-22T11:12:38.760Z caller=collector.go:136 level=error msg="Failed to execute jsonpath" err="description is not found" path={.description} data=""All good""
>
> json_exporter | ts=2023-06-22T11:12:38.761Z caller=collector.go:88 level=error msg="Failed to extract value for metric" path={.description} err="description is not found" metric="Desc{fqName: "jsonhc_description", help: "healthcheks description", constLabels: {}, variableLabels: [env]}
The data I get is correct, but I can't take it for an alert. When I check the curl for targets, it's not there.
I ran:
#curl http://localhost:7979/probe
And received:
> Target parameter is missing
I've tried different variants of the path
variable (such as '$.*' and '{ [*] }'
) but it doesn't work. Please help me figure it out is this a bug or am I doing something wrong?
答案1
得分: 0
以下是翻译好的部分:
问题出在Healthcheck本身。这是它应该是的内容。
{
"healthcheck": [
{
"status": "OK",
"description": "一切正常",
"sql": null
}
]
}
之后,模块按照我想要的方式工作了。
另外,为了实现我心目中的功能,我需要一个类似这样的模块。
path: '{.healthcheck[?(@.status != "OK")]}'
然后,如果状态不是"OK",我设置了一个警报,以便在状态等于1时发送电子邮件通知我。
英文:
So the problem was with Healthcheck itself. This is what it was supposed to be.
{
"healthcheck": [
{
"status": "OK",
"description": "All good",
"sql": null
}
]
}
After that the module worked as I wanted it to.
Also, to do what I had in mind, I needed a module like this.
path: '{.healthcheck[?(@.status != "OK")]}'
And then in case there was not "OK", I set up an alert so that I would be sent an email when the status == 1
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论