我想将 Apache HTTPd 日志统计信息(例如 200 个状态计数)发送到 Graphite/Carbon。Logstash 看起来很理想,但我见过的所有示例都使用 Statsd 充当状态计数器。这意味着启动 Statsd 服务器(或在 Collectd 5.x 中启用 Statsd)。
Logstash 有没有办法将计数器直接写入 Graphite/carbon?
答案1
是的,使用 logstash 中的“metric”过滤器。在默认配置中,它将针对给定字段每 5 秒发出一次度量事件。通过每 5 秒重置一次计数器,您可以将数据直接发送到 Graphite 的 carbon 服务器进行存储。
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"
]
}