gpt4 book ai didi

elasticsearch - 内联脚本包含算术的观察者条件失败

转载 作者:行者123 更新时间:2023-12-03 01:20:39 25 4
gpt4 key购买 nike

我正在尝试创建一个监视程序,该监视程序将在我使用80%以上的JVM堆时触发。

我正在对Elasticsearch v7.5进行以下查询。

{
"trigger": {
"schedule": {
"interval": "20s"
}
},
"input": {
"http": {
"request": {
"scheme": "https",
"host": "domain.region.aws",
"port": 9200,
"method": "get",
"path": "/_cluster/stats"
"params": {},
"headers": {},
"auth": {
"basic": {
"username": "username",
"password": "password"
}
}
}
}
},
"condition": {
"script": {
"inline": "return ((ctx.payload.nodes.jvm.mem.heap_used_in_bytes / ctx.payload.nodes.jvm.mem.heap_max_in_bytes) * 100) > 80"
}
},
"actions": {
"send_email": {
"email": {
"to": "some-email@domain.com",
"subject": "Watcher Notification",
"body": "{{ctx.payload.nodes.jvm.mem.heap_used_in_bytes}} of the JVM heap memory is currently being used."
}
}
}
}

我的情况似乎返回了错误的结果。

例如:

如果我将脚本更改为:
return ((ctx.payload.nodes.jvm.mem.heap_used_in_bytes / ctx.payload.nodes.jvm.mem.heap_max_in_bytes) * 100) < 1 heap_used_in_bytes = 979683712
heap_max_in_bytes = 2739011584

这应导致:35.767782719(错误)

结果包含以下内容(不正确):
"condition": {
"type": "script",
"status": "success",
"met": true
}

看来,即使我尝试使用变量进行简单查询,也无法正常工作。例如,将条件更改为 return ctx.payload.nodes.jvm.mem.heap_max_in_bytes > 2739011584会导致奇怪的编译错误:
{"statusCode":400,"error":"Bad Request","message":"[script_exception] compile error, with { script_stack={ 0=\"... vm.mem.heap_max_in_bytes 2739011584\" & 1=\"                             ^---- HERE\" } & script=\"return ctx.payload.nodes.jvm.mem.heap_max_in_bytes 2739011584\" & lang=\"painless\" }"}

我不使用变量的简单比较似乎是可行的。我可以在 body操作中以 email的值来打印在脚本中访问的变量的值。谁能说明一下这里发生的事情吗?无论如何,是否可以在电子邮件正文中的某个位置打印此脚本的结果?

最佳答案

根据该错误消息,这不是使用Groovy,而是使用默认的ES语言painless
根据painless documentation,整数除法将得出整数,因此979683712 / 2739011584 == 0
我不是专家,但是I believe将您的无痛脚本更改为:

return ((ctx.payload.nodes.jvm.mem.heap_used_in_bytes / (double)ctx.payload.nodes.jvm.mem.heap_max_in_bytes) * 100) < 1

应该修复它(因为它将除法的分母转换为 double)

或者,您应该可以执行以下操作:
    "condition": {
"script": {
"lang": "groovy",
"inline": "return ((ctx.payload.nodes.jvm.mem.heap_used_in_bytes / ctx.payload.nodes.jvm.mem.heap_max_in_bytes) * 100) > 80"
}
},

要改用groovy ...

希望有帮助...无法轻松测试test

关于elasticsearch - 内联脚本包含算术的观察者条件失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60319209/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com