2014-10-17 64 views
2

我使用logstash(1.4.2在centos上)使用度量过滤器和石墨输出来绘制访问日志HTTP响应代码。logstash石墨输出使用变量度量名称

基本配置工程。这是我的工作配置文件。

input { 
    file { 
    path => "/var/log/nginx/access.log" 
    } 
} 
filter { 
    grok { 
    match => { "message" => "%{COMBINEDAPACHELOG}" } 
    } 
    date { 
    match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ] 
    } 
    metrics { 
    meter => [ "http.%{response}" ] 
    add_tag => "metrics" 
    } 
} 
output { 
    if "metrics" in [tags] { 
    graphite { 
     host => "localhost" 
     port => "2003" 
     metrics => [ "mymetric.http.200", "%{http.200.rate_1m}"] 
    } 
    } 
} 

并且输出显示正确,例如,

mymetric.http.200 0.8430647815095349 1413557739 

不过,我想安装在多台服务器(主机)的相同配置文件,包括在度量标准名称的主机名。

我尝试在度量标准定义中使用%{host}变量,例如

metrics => [ "mymetric.%{host}.http.200", "%{http.200.rate_1m}" ] 

但这不发送任何石墨和我在logstash调试输出得到

"Message is empty..." 

。有任何想法吗?

回答

1

我目前有类似的问题。作为解决方案,我添加了我想要的电表定义的模式。

meter => [ "mymetric.%{host}.http.%{response}" ] 

要测试什么是石墨,你可以使用石墨编解码器的输出。

stdout { 
    codec => graphite { 
     fields_are_metrics => true 
    } 
}