Logstash配置——變量的使用

前置條件:Linux Logstash 5.5.0(其餘版本請查閱一下文檔)json

使用logstash把日誌從文件輸出到文件,根據輸入文件的路徑,肯定輸出文件的文件名。配置以下:app

input {
    stdin{}
    file {
        path => "/tmp/app1/instance1/access.log"
        start_position => "beginning"
    }
}
filter {
    grok {
        match => {
            "path" => "(?<app_name>app\d?)"
        }
    }
    grok {
        match => {
            "path" => "(?<app_instance>instance\d?)"
        }
    }
    grok {
        match => {
            "message" => "^(?<request_time>\d{4}-\d{2}-\d{2})\t"
        }
    }

}
output {
    stdout {
        codec => "json"
    }
    file {
        codec => "json"
        path => "/tmp/%{app_name}_%{app_instance}_%{request_time}.olog"
    }
}日誌

若是不想用多個grok,能夠配置一個grok,而後將屬性break_on_match設置爲false。code

grok {文檔

        break_on_match => false
        match => {
            "path" => "(?<app_name>app\d?)"input

            "path" => "(?<app_instance>instance\d?)"it

            "message" => "^(?<request_time>\d{4}-\d{2}-\d{2})\t"
        }
    }io

相關文章
相關標籤/搜索