Grok 模式从日志字符串中删除“ms”并转换为 INT

问题描述 投票:0回答:1

第一次好久了。

我有这个日志消息:

2022/05/04 09:24:08 INTERESTING UpdateStatus: active: 45 waiting: 0 connections: 91 max dbcmd queue length: 3 max dbcmd response time: 19ms cmds processed: 6 nacks: 0 nresent: 0

我有这个 grok 模式来解析它:

%{DATE} %{TIME} %{WORD:log_level} %{WORD:update_status}: active: %{INT:active} waiting: %{INT:waiting} connections: %{INT:connections} max dbcmd queue length: %{NUMBER:max_dbcmd_queue_length} max dbcmd response time: %{WORD:max_dbcmd_response_time} cmds processed: %{NUMBER:cmds_processed} nacks: %{NUMBER:nacks} nresent: %{NUMBER:nresent}

除了一件事之外,一切都很好,

我想提取这个值的响应时间并绘制 int (19) 的图表。

max dbcmd response time: 19ms

但是我能让 grok 开心的唯一方法就是把它变成一个单词,因为“ms”。

max dbcmd response time: %{WORD:max_dbcmd_response_time}

我真的希望 19 成为一个 INT,但我不知道如何删除或忽略标记在数字“19ms”末尾的“ms”。

regex parsing logging grok
1个回答
1
投票

您可以使用

INT
,但需要在图案部分后添加
ms
\w*

%{INT:max_dbcmd_response_time}ms
%{INT:max_dbcmd_response_time}\w*

完整图案:

%{DATE} %{TIME} %{WORD:log_level} %{WORD:update_status}: active: %{INT:active} waiting: %{INT:waiting} connections: %{INT:connections} max dbcmd queue length: %{NUMBER:max_dbcmd_queue_length} max dbcmd response time: %{INT:max_dbcmd_response_time}ms cmds processed: %{NUMBER:cmds_processed} nacks: %{NUMBER:nacks} nresent: %{NUMBER:nresent}

或者

%{DATE} %{TIME} %{WORD:log_level} %{WORD:update_status}: active: %{INT:active} waiting: %{INT:waiting} connections: %{INT:connections} max dbcmd queue length: %{NUMBER:max_dbcmd_queue_length} max dbcmd response time: %{INT:max_dbcmd_response_time}\w* cmds processed: %{NUMBER:cmds_processed} nacks: %{NUMBER:nacks} nresent: %{NUMBER:nresent}
© www.soinside.com 2019 - 2024. All rights reserved.