簡體   English   中英

從日志字符串中刪除“ms”並轉換為 INT 的 Grok 模式

[英]Grok pattern to remove "ms" from log string and convert to INT

第一次很長時間。

我有這條日志消息:

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”而使它成為一個 WORD。

max dbcmd response time: %{WORD:max_dbcmd_response_time}

我真的希望 19 成為一個 INT,但我不知道如何刪除或忽略標記在數字“19ms”末尾的“ms”。

您可以使用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}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM