通过Grok导出器读取XML文件

时间:2018-09-26 09:46:47

标签: xml grok

我正在使用Grok导出器来找出错误行。 我能够使用.log文件做到这一点。 但是,每当我尝试对XML文件使用相同的文件时,都不会得到期望的结果。

**

  • 例如:-

以下是我的日志文件:-

  2016/07/30 14:37:03 alice 1.5
    30.07.2016 14:37:33 Adam 2.5
    30.07.2016 14:43:02 bob 3.5
    30.07.2016 14:45:59 Bill 4.5
    31.07.2018 14:45:59 Baren 5.5
    30.07.2018 14:45:59 Joe 6.5
    30.07.2018 14:45:59 Right 7.5
    30.07.2018 14:45:59 Jess 8.5
    30-07-2018 14:45:59 Nathan 9.5
    30.07.2018 15:45:59 Suzi 10.5

Grok配置文件:-

    input:
        type: file
        path: ./example/example.log
        readall: true
    grok:
        patterns_dir: ./patterns
    metrics:
        - type: counter
          name: grok_example_lines_total
          help: Example counter metric with labels.
          match: '%{DATE} %{TIME} %{USER} %{NUMBER}'
    server:
        host: localhost
        port: 9144

输出:-

    # TYPE grok_exporter_lines_total counter
    grok_exporter_lines_total{status="ignored"} 1
    grok_exporter_lines_total{status="matched"} 9

当我尝试处理xml文件时,所有事情都被忽略。 XML代码:-

   <Cat>Exception</Cat>
          <DateTime>2017-02-17T21:12:44.4677331-02:00</DateTime>

Grok配置文件:-

input:
    type: file
    path: ./example/example.xml
    readall: true
grok:
    patterns_dir: ./patterns
metrics:
    - type: counter
      name: grok_example_lines_total
      help: Example counter metric with labels.
      match: '%{TIMESTAMP_ISO8601}'
server:
    host: localhost
    port: 9144

在Grok调试器中,grok表达式与2017-02-17T21:12:44.4677331-02:00匹配,但是,在指标中所有行都被忽略 输出:-

# TYPE grok_exporter_lines_total counter
grok_exporter_lines_total{status="ignored"} 5
grok_exporter_lines_total{status="matched"} 0

**

1 个答案:

答案 0 :(得分:0)

不幸的是,grok_exporter的创建者在fstab/grok_exporter#46上说,grok_exporter不支持多行捕获。

  

grok_exporter不支持多行模式。原因是   grok_exporter逐行处理日志文件。每当换行   写入日志文件,将模式应用于新行   仅,指标会相应更新。我不认为有   支持多行模式的一种直接方法,因为   表示如果将新行写入日志文件,则整个   文件必须重新处理。

Logstash是一种替代方案,具有多个编解码器插件供您使用。

https://www.elastic.co/guide/en/logstash/current/plugins-codecs-multiline.html#plugins-codecs-multiline

相关问题