如何在Graphite中绘制Apache HTTPd状态计数而不使用Logstash统计?

我想发送Apache HTTPd日志统计信息,例如200个状态计数到Graphite / Carbon。 Logstash看起来很理想,但是我所见过的所有例子都使用Statsd作为状态计数器。 这意味着启动一个Statsd服务器(或在Collectd 5.x中启用Statsd)。

Logstash是否有办法直接将计数器写入Graphite / Carbon?

是的,在logstash中使用“度量”filter。 在默认configuration中,它会每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秒钟,将创build以下事件:

 { "@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" ] }