0

我在 Elasticsearch 中创建了一个手表,如果在 60 分钟内 http 错误的比率大于总请求的 15%,我会提醒我。我正在使用链输入来为我的比率计算生成被除数和除数值。

在我的情况下,我使用脚本进行除法并检查它是否大于我的比率。

但是,每当我使用 2 个 ctx 参数进行除法时,它总是等于零。

如果我使用它并且只使用 ctx 参数之一,那么它可以正常工作。

似乎我们不能在一个条件下使用 2 个 ctx 参数。

有谁知道如何解决这个问题?

下面是我的手表。

谢谢。

{
  "trigger" : {
    "schedule" : {
      "interval" : "5m"
    }
  },
  "input" : {
    "chain":{
      "inputs": [
      {
        "first": {
          "search" : {
            "request" : {
              "indices" : [ "logstash-*" ],
              "body" : {
                "query" : { 
                  "bool":{
                    "must": [
                      {
                      "match" : {"d.uri": "xxxxxxxx"}
                      },
                      { 
                      "match" : {"topic": "xxxxxxxx"}
                      }
                    ],
                    "filter": {
                      "range": {
                        "@timestamp": {
                          "gte": "now-60m"
                        }
                      }
                    }
                  }
                }
              }
            },
            "extract": ["hits.total"]
          }
        }
      },
      {
        "second": {
          "search" : {
            "request" : {
              "body" : {
                "query" : { 
                  "bool":{
                    "must": [
                      {
                      "match" : {"d.uri": "xxxxxxxx"}
                      },
                      { 
                      "match" : {"topic": "xxxxxxxx"}
                      },
                      { 
                      "match" : {"d.status": "401"}
                      }
                    ],
                    "filter": {
                      "range": {
                        "@timestamp": {
                          "gte": "now-60m"
                        }
                      }
                    }
                  }
                }
              }
            },
            "extract": ["hits.total"]
          }
        }
      }
      ]
    }
  },
  "condition" : {
    "script" : {
      "source" : "return (ctx.payload.second.hits.total / ctx.payload.first.hits.total) == 0"
    }
  }
}
4

1 回答 1

0

这个问题实际上来自于我正在做一个整数除法以获得0.xx形式的比率。我颠倒了操作,它工作正常。

于 2017-09-15T14:08:18.167 回答