elasticsearch 包含算术的内联脚本的观察者条件失败
我正在尝试创建一个监视程序,每当我使用超过80%的JVM堆时,它就会启动 我对elasticsearch v7.5进行以下查询elasticsearch 包含算术的内联脚本的观察者条件失败,elasticsearch,groovy,lucene,elasticsearch,Groovy,Lucene,我正在尝试创建一个监视程序,每当我使用超过80%的JVM堆时,它就会启动 我对elasticsearch v7.5进行以下查询 { "trigger": { "schedule": { "interval": "20s" } }, "input": { "http": { "request": { "scheme": "https",
{
"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."
}
}
}
}
我的情况似乎返回了错误的结果
例如:
如果我将脚本更改为:
返回ctx.payload.nodes.jvm.mem.heap_used_in_bytes/ctx.payload.nodes.jvm.mem.heap_max_in_bytes*100<1
使用的堆字节数=979683712
堆最大字节数=2739011584
这将导致:35.767782719错误
导致响应包含不正确的内容:
"condition": {
"type": "script",
"status": "success",
"met": true
}
当我尝试使用变量进行简单查询时,似乎都不起作用。例如,更改条件以返回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值中打印脚本中访问的变量值。谁能解释一下这里发生了什么事吗?还有,在电子邮件正文的某个地方是否可以打印此脚本的结果?根据该错误消息,这不是使用Groovy,而是使用默认的ES语言,这是毫无痛苦的 根据,整数除法将产生一个整数,因此979683712/2739011584==0 我不是专家,但将您的无痛脚本更改为:
return ((ctx.payload.nodes.jvm.mem.heap_used_in_bytes / (double)ctx.payload.nodes.jvm.mem.heap_max_in_bytes) * 100) < 1
要改用groovy
希望这有助于。。。无法轻松测试谢谢Tim,就是这样。。!按照您建议的将无痛脚本更改为双精度已解决问题。
"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"
}
},