Logstash

發生 1000 次後的 logstash 警報

  • February 4, 2016

我試圖讓 Logstash 僅在 10 分鐘內收到超過 1000 個項目後才提醒我。我需要 Hipchat 和 PagerDuty 中的警報。

我的配置看起來很合理,但沒有按預期工作。

filter {
   if my_filtering_conditional_that_is_100%_correct {
       throttle {
           before_count => 1000
           period => 600
           add_tag => ["PD"]
           key => "string"
       }
       clone {
           add_tag => ["Count"]
       }
   }
   if "Count" in [tags] {
       throttle {
           before_count => 1000
           period => 600
           add_tag => ["HC"]
           key => "string"
       }
   }
}

output {
   if "PD" in [tags] {
        pagerduty {
           event_type => trigger
           incident_key => "logstash/Logstash"
           service_key => Pagerduty_API_key
           workers => 1
           description => "Alert message"
       }
   }
   if "HC" in [tags] {
       hipchat {
           color => "random"
           from => "Logstash"
           format => "Alert message"
           room_id => "Room"
           token => "token"
       }
   }
}

使用指標過濾器可能會取得更好的成功。

filter {
 my_filtering_conditional_that_is_100%_correct {
   metrics {
     meter => [ "events" ]
     flush_interval => 600
     clear_interval => 600
     add_tag => "events"
   }
 }
}

output {
 if "events" in [tags] {
   if [events][count] > 1000 {
     # do things
   }
 }
}

我認為您最好的選擇是使用http://riemann.io/。它處理事件“流”,這種邏輯在那裡表示起來並不難。

當某種類型的事件超過 5 個時,以下連結上的範例會創建警報:

(streams
 (where (<= 0 metric 5)
   (with :state "ok" index)
   (else
     (with :state "warning" index))))

http://riemann.io/howto.html#set-thresholds

問候,

引用自:https://serverfault.com/questions/691755