使用Regex的AWS Cloudwatch Log Insights查询不会为MySql慢查询日志提取列

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

[当我在AWS Cloudwatch Log Insights中运行以下查询时,输出为空

parse @message /Query_time: (?<Query_time>[0-9](\.[0-9]+)?), Lock_time: (?<Lock_time>[0-9](\.[0-9]+)?), (?<Query>(?<=\;)(.*?)(?=\;))/ 

enter image description here

但是如果我单独运行每个枚举,它的确会提取值

parse @message /Query_time: (?<Query_time>[0-9](\.[0-9]+)?)/

enter image description here

# User@Host: ****[****] @ localhost [] Id: 10
# Query_time: 0.000283 Lock_time: 0.000075 Rows_sent: 1 Rows_examined: 1
SET timestamp=1589784518; SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'TIME_SINCE_ZERO_CONNECTIONS';

我是否缺少某些东西

regex amazon-cloudwatchlogs
1个回答
1
投票
您可以使用

Query_time:\s*(?<Query_time>[0-9]+(?:\.[0-9]+)?)\s*Lock_time:\s*(?<Lock_time>[0-9]+(?:\.[0-9]+)?)[\s\S]*?;\s*(?<Query>[^;]*)

请参见regex demo。详细信息:

    Query_time:-文字字符串
  • \s*-任意0+空格
  • [(?<Query_time>[0-9]+(?:\.[0-9]+)?)-组“ Query_time”:浮点数或类似整数的数字
  • \s*-任意0+空格
  • Lock_time:-文字字符串
  • \s*-任意0+空格
  • [(?<Lock_time>[0-9]+(?:\.[0-9]+)?)-组“ Lock_time”:浮点数或类似整数的数字
  • [[\s\S]*?-任何0+个字符,包括换行符,应尽可能少]
  • [;-分号
  • \s*-0+空格
  • [(?<Query>[^;]*)-组“查询”:除;以外的任何0个或多个字符。
© www.soinside.com 2019 - 2024. All rights reserved.