2017-09-14 42 views
0

我在Elasticsearch中創建了一個監視器,以便在60分鐘內HTTP錯誤的比率大於總請求的15%時提醒我。 我正在使用鏈式輸入來生成我的比率計算的除數和除數值。無法在Elasticsearch觀察器中劃分多個上下文值

在我的情況下,我正在使用腳本執行除法並檢查它是否大於我的比例。

但是,無論何時我使用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" 
    } 
    } 
} 

回答

0

這個問題實際上來自於我正在做一個整數除法以達到0.xx形式的比率。 我扭轉了操作,它工作正常。

相關問題