【问题标题】:fluentd filter regex pattern gives an invalid strptime format errorfluentd 过滤器正则表达式模式给出了无效的 strptime 格式错误
【发布时间】:2017-07-07 05:56:28
【问题描述】:

我正在尝试使用正则表达式过滤器来解析我的日志 我的正则表达式和示例字符串如下 正则表达式:

/^(?<logtime>[^\|]*)\S +(?<cpu-usr>\S+) +(?<cpu-sys>\S+) +(?<cpu-idl>\S+) +(?<cpu-wai>\S+) +(?<cpu-hiq>\S+) +(?<cpu-siq>[^|]+)\S +(?<mem-used>\S+) +(?<mem-buff>\S+) +(?<mem-cach>\S+) +(?<mem-free>\S+)/

示例字符串:

07-07 17:18:12|  0   0 100   0   0   0| 197M 48.9M  182M  546M

所以我在 fluent.conf 文件中编写了以下过滤器

#filter dstat log into fields. 
#----system---- ----total-cpu-usage---- ------memory-usage-----
#  date/time   |usr sys idl wai hiq siq| used  buff  cach  free
<filter input.dstat>
  @type parser
  format /^(?<logtime>[^\|]*)\S +(?<cpu-usr>\S+) +(?<cpu-sys>\S+) +(?<cpu-idl>\S+) +(?<cpu-wai>\S+) +(?<cpu-hiq>\S+) +(?<cpu-siq>[^|]+)\S +(?<mem-used>\S+) +(?<mem-buff>\S+) +(?<mem-cach>\S+) +(?<mem-free>\S+)/
  time_format %d-%m %H:%M:%S
  time_key logtime
  keep_time_key true
  key_name log
</filter>

但是,我收到此过滤器的以下错误。

fluentd_1 | 2017-07-07 05:42:36 +0000 [警告]:无效的时间格式:值 = 07-0,error_class= ArgumentError,错误 = 无效的 strptime 格式 - `%d-%m %H:%M:%S '

我已经使用http://fluentular.herokuapp.com/ 检查了正则表达式和时间格式,据此看来还可以。我该如何处理?我目前的假设是错误是由于时间格式中缺少 %Y 或年份。但是我的日志不包含年份信息。

【问题讨论】:

    标签: regex fluentd


    【解决方案1】:

    问题是我在名称中使用了“-”而不是“_” 更换后就可以正常使用了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-14
      • 1970-01-01
      • 2021-10-15
      • 1970-01-01
      • 2021-06-10
      • 2017-02-27
      • 1970-01-01
      • 2021-02-01
      相关资源
      最近更新 更多