使用logstash已用过的库过滤日志文件

时间:2014-10-06 16:59:38

标签: regex logstash elapsed

我正在尝试过滤以下日志文​​件:

+---------+---------+---------+---------+---------+---------+---------+----
.Logon hostname/username,

 *** Logon successfully completed.
 *** Teradata Database Release is 14.00.06.05
 *** Teradata Database Version is 14.00.06.05
 *** Transaction Semantics are BTET.
 *** Session Character Set Name is 'ASCII'.

 *** Total elapsed time was 1 second.

+---------+---------+---------+---------+---------+---------+---------+----
select current_timestamp as started_test;

 *** Query completed. One row found. One column returned.
 *** Total elapsed time was 1 second.

                    started_test
--------------------------------
2014-10-06 17:44:39.220000+00:00

+---------+---------+---------+---------+---------+---------+---------+----
select * from database.view sample 2;

 *** Query completed. 2 rows found. 41 columns returned.
 *** Total elapsed time was 2 seconds.


select current_timestamp as finished_test;

 *** Query completed. One row found. One column returned.
 *** Total elapsed time was 1 second.

                   finished_test
--------------------------------
2014-10-06 17:44:41.330000+00:00

使用此logstash过滤器

input{
        file {
                path => "/home/iv41/perfmon.log"
        }
        stdin {}
}

filter {
        grok{
                match => ["message", "%{/\s+started_test/:start_time} START id: (?<task_id>.*)"]
                add_tag => ["testStarted"]
        }

        grok{
                match => ["message", "%{/\s+finished_test/:end_time} END id: (?<task_id>.*)"]
                add_tag => ["testEnded"]
        }

        if [start_time] != "/\s+started_test/"{
                if [end_time] != "/\s+finished_test/"{
                        drop {}
                }
        }

        elapsed {
                start_tag => "testStarted"
                end_tag => "testEnded"
                unique_id_field => "task_id"
        }
}

output{
        stdout {}
}

我认为我的正则表达式和任务ID可能存在问题。

基本上,我试图将“started_test”和“finished_test”之间的时间拉出来。有谁知道更好的方法吗?或者知道我的代码在哪里?

0 个答案:

没有答案