【问题标题】:Parse and forward jenkins build logs to logstash/ elastricsearch解析并转发 jenkins 构建日志到 logstash/elastricsearch
【发布时间】:2019-08-28 02:24:28
【问题描述】:

使用 filebeat 将 Jenkins 构建日志转发到 logstash/elasticsearch

目前我在 jenkins 服务器上将 filebeat 作为服务运行,并且能够将日志传递到 logstash/elasticsearch。

filebeat:
  prospectors:
    - paths:
        - "/var/jenkins_home/jobs/*/builds/*/log"

output:
  logstash:
    hosts: ["172.22.0.4:5044"]
    index: "jenkins"


Jenkins log file:
Started by user ha:////4Pt==anonymous
Building in workspace /var/jenkins_home/jobs/aaa/workspace
[workspace] $ /bin/sh -xe /tmp/jenkins2734923241755751652.sh
+ maven install
/tmp/jenkins2734923241755751652.sh: 2: 
/tmp/jenkins2734923241755751652.sh: maven: not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE
  • 如何将整个构建日志作为单个文档发送。目前它 在 elastricsearch 中将每个日志行作为一行。
  • 如何在 elastricsearch 文档中添加“已完成”作为字段。

【问题讨论】:

    标签: elasticsearch jenkins logstash filebeat


    【解决方案1】:

    不确定您是否要这样做,但可能会考虑实现多行模式: https://www.elastic.co/guide/en/beats/filebeat/master/multiline-examples.html

    它将根据您的配置方式组合日志行,主要用于异常和堆栈跟踪,但您可能可以为您的 Jenkins 构建日志设置一个。

    在您的构建日志示例中,以“Started by”开头,您可以使用以下模式和 multiline.negate 的值“true”: ^Started by

    这是 go 操场上的一个示例,听起来您希望多行模式“匹配”除第一行之外的所有内容,以便它将所有行合并到最上面的行中,这就是我的设置方式: https://play.golang.org/p/W1on5dxNJTq

    对于“已完成”字段,可以使用具有 add_field 选项的 mutate 插件在 Logstash 中轻松完成: https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html#plugins-filters-mutate-add_field

    请注意,add_field 选项是一个常用选项,可以在多个地方完成,包括输入插件,例如beat inputgrok filter

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-07
      相关资源
      最近更新 更多