简体   繁体   English

使用带有Logstash的grok的自定义指标

[英]Custom metrics using grok with logstash

I'm trying to integrate some code into an existing ELK stack, and we're limited to using filebeats + logstash. 我正在尝试将一些代码集成到现有的ELK堆栈中,我们仅限于使用filebeats + logstash。 I'd like to have a way to configure a grok filter that will allow different developers to log messages in a pre-defined format such that they can capture custom metrics, and eventually build kibana dashboards. 我希望有一种配置grok过滤器的方法,该过滤器将允许不同的开发人员以预定义的格式记录消息,以便他们可以捕获自定义指标,并最终构建kibana仪表板。

For example, one team might log the following messages: 例如,一个团队可能会记录以下消息:

metric_some.metric=2
metric_some.metric=5
metric_some.metric=3

And another team might log the following messages from another app: 另一个团队可能会从另一个应用程序记录以下消息:

metric_another.unrelated.value=17.2
metric_another.unrelated.value=14.2

Is there a way to configure a single grok filter that will capture everything after metric_ as a new field, along with the value? 有没有一种配置单个grok过滤器的方法,该过滤器会将metric_之后的所有内容与值一起捕获为新字段? Everything I've read here seem to indicate that you need to know the field name ahead of time, but my goal is to be able to start logging new metrics without having to add/modify grok filters. 我在这里阅读的所有内容似乎都表明您需要提前知道字段名称,但是我的目标是能够开始记录新指标,而不必添加/修改grok过滤器。

Note: I realize Metricsbeat is probably a better solution here, but as we're integrating with an existing ELK cluster which we do not control, that's not an option for me. 注意:我意识到Metricsbeat在这里可能是一个更好的解决方案,但是由于我们正在与一个我们无法控制的现有ELK集群进行集成,因此这不是我的选择。

As your messages seems to be a series of key-value pairs, you can use the kv filter instead of grok . 由于您的消息似乎是一系列键值对,因此可以使用kv过滤器代替grok

When using grok you need to name the destination field, with kv the name of the destination field will be the same as the key . 使用grok您需要命名目标字段,用kv命名目标字段的名称将与key相同。

The following configuration should work for your case. 以下配置应适合您的情况。

filter { kv { prefix => "metric_" } }

For the event metric_another.unrelated.value=17.2 your output will be something like { "another.unrelated.value": "17.2" } 对于事件metric_another.unrelated.value=17.2您的输出将类似于{ "another.unrelated.value": "17.2" }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM