Logstash
如何在沒有 Statsd 的情況下使用 Logstash 在 Graphite 中繪製 Apache HTTPd 狀態計數?
我想向 Graphite/Carbon 發送 Apache HTTPd 日誌統計資訊,例如 200 個狀態計數。Logstash 看起來很理想,但我見過的所有範例都使用 Statsd 作為狀態計數器。這意味著啟動 Statsd 伺服器(或在 Collectd 5.x 中啟用 Statsd)。
Logstash 有沒有辦法直接將計數器寫入石墨/碳?
是的,在 logstash 中使用“metric”過濾器。在預設配置中,它將每 5 秒為給定欄位發出一次度量事件。通過每 5 秒重置一次計數器,您可以將數據直接發送到 Graphite 的碳伺服器進行儲存。
input { file { path => "/var/log/apache2/access.log" } } filter { grok { match => { "message" => "%{COMBINEDAPACHELOG}" } } date { match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ] } # make sure response code is valid if [response] =~ /\d\d\d/ { metrics { # A counter field meter => "apache.response.%{host}.%{response}" add_tag => "metric" clear_interval => "5" flush_interval => "5" } } } output { #stdout { codec => rubydebug } graphite { fields_are_metrics => true # only send metrics collected in the filter include_metrics => ["^apache\.response\..*"] #host => "localhost" #port => "2003" } }
每 5 秒創建一次以下事件:
{ "@version" => "1", "@timestamp" => "2015-05-26T11:38:15.510Z", "message" => "ip-10-0-0-148", "apache.response.ip-10-0-0-145.401.count" => 1, "apache.response.ip-10-0-0-145.401.rate_1m" => 0.0, "apache.response.ip-10-0-0-145.401.rate_5m" => 0.0, "apache.response.ip-10-0-0-145.401.rate_15m" => 0.0, "tags" => [ [0] "metric" ] }