logstash grok multiline - 如何将任何不以时间戳开头的行合并到上一行

时间:2015-07-21 12:09:37

标签: logstash multiline grok

有时我打印以记录以多行打印的缩进的漂亮jsons。所以我需要能够告诉logstash将这些打印附加到原始事件的原始行。

示例:

xxx p:INFO d:2015-07-21 11:11:58,906 sourceThread:3iMind-Atlas-akka.actor.default-dispatcher-2 queryUserId: queryId: hrvJobId:6c1a4d60-e5e6-40d8-80aa-a4dc00e9f0c4 etlStreamId:70 etlOmdId: etlDocId: logger:tim.atlas.module.etl.mq.MQConnectorEtl msg:(st:Consuming) received NotifyMQ. sending to [openmind_exchange/job_ack] message:
{
  "JobId" : "6c1a4d60-e5e6-40d8-80aa-a4dc00e9f0c4",
  "Time" : "2015-07-21T11:11:58.904Z",
  "Errors" : [ ],
  "FeedItemSchemaCounts" : {
    "Document" : 1,
    "DocumentMetadata" : 1
  },
  "OtherSchemaCounts" : { }
}

由于我已经设置了一个特殊的log4j appender来仅仅作为logstash输入,因此该任务应该很容易安静。我控制日志的布局,所以我可以添加尽可能多的前缀/后缀指示符。

这是我的追随者的样子:

log4j.appender.logstash-input.layout.ConversionPattern=xxx p:%p d:%d{yyyy-MM-dd HH:mm:ss,SSS}{UTC} sourceThread:%X{sourceThread} queryUserId:%X{userId} queryId:%X{queryId} hrvJobId:%X{hrvJobId} etlStreamId:%X{etlStreamId} etlOmdId:%X{etlOmdId} etlDocId:%X{etlDocId} logger:%c msg:%m%n

正如您所看到的,我已经为每条消息添加了&x 39; xxx'所以我可以告诉logstash追加任何不以' xxx'开头的行。到上一行

这是我的logstash配置:

if [type] == "om-svc-atlas" {
    grok {
        match => [ "message" , "(?m)p:%{LOGLEVEL:loglevel} d:%{TIMESTAMP_ISO8601:logdate} sourceThread:%{GREEDYDATA:sourceThread} queryUserId:%{GREEDYDATA:userId} queryId:%{GREEDYDATA:queryId} hrvJobId:%{GREEDYDATA:hrvJobId} etlStreamId:%{GREEDYDATA:etlStreamId} etlOmdId:%{GREEDYDATA:etlOmdId} etlDocId:%{GREEDYDATA:etlDocId} logger:%{GREEDYDATA:logger} msg:%{GREEDYDATA:msg}" ]
        add_tag => "om-svc-atlas"
    }
    date {
        match => [ "logdate" , "YYYY-MM-dd HH:mm:ss,SSS" ]
        timezone => "UTC"
    }
    multiline {
        pattern => "<please tell me what to put here to tell logstash to append any line which doesnt start with xxx to the previous line>"
        what => "previous"
    }
  }

1 个答案:

答案 0 :(得分:2)

是的确很容易:

def originalWar = file("../release/${sesame_version}/war/openrdf-sesame.war")
def outputDir = "./build/war"
def outputDirSesame = "$outputDir/sesame"

task extractWar(type: Copy) {
    from zipTree(originalWar)
    into "$outputDirSesame"
    outputs.upToDateWhen { false }
}

task copyJar(type: Copy, dependsOn: extractWar) {  
    from "./build/libs"
    into "$outputDirSesame/WEB-INF/lib"
    outputs.upToDateWhen { false }
}

task buildWar(type: Zip, dependsOn: copyJar) {
    archiveName "openrdf-sesame.war"
    destinationDir file("$outputDir")
    from "$outputDirSesame"
    outputs.upToDateWhen { false }
}

build.dependsOn buildWar