Convert timestamp timezone in Logstash for output index name

后端 未结 4 1318
一个人的身影
一个人的身影 2021-01-01 02:47

In my scenario, the \"timestamp\" of the syslog lines Logstash receives is in UTC and we use the event \"timestamp\" in the Elasticsearch output:

output {
           


        
相关标签:
4条回答
  • In Logstash Version 5.0.2,The API was modified. We can convert timestamp by local timezone for the index name. Here is my configuration:

    filter { 
       ruby { 
           code => "event['index_day'] = event.timestamp.time.localtime.strftime('%Y.%m.%d')" 
       } 
    } 
    
    0 讨论(0)
  • 2021-01-01 03:23

    This is the optimize config, please have a try and test for the performance.

    You no need to use mutate and date plugin. Use ruby plugin directly.

    input {
        stdin {
        }
    }
    
    filter {
        ruby {
                code => "
                        event['index_day'] = event['@timestamp'].localtime.strftime('%Y.%m.%d')
                "
        }
    }
    
    output {
        stdout { codec => rubydebug }
    }
    

    Example output:

    {
           "message" => "test",
          "@version" => "1",
        "@timestamp" => "2015-03-30T05:27:06.310Z",
              "host" => "BEN_LIM",
         "index_day" => "2015.03.29"
    }
    
    0 讨论(0)
  • 2021-01-01 03:24

    In version 1.5.0, we can convert timestamp by local timezone for the index name. Here is my configuration:

    filter {
        ruby {
            code => "event['index_day'] = event.timestamp.time.localtime.strftime('%Y.%m.%d')"
        }
    }
    output {
        elasticsearch {
            host => localhost
            index => "thrall-%{index_day}"
        }
    }
    
    0 讨论(0)
  • 2021-01-01 03:26

    In logstash version 5.0 and later, you can use this:

    filter{
    ruby {
            code => "event.set('index_day', event.get('[@timestamp]').time.localtime.strftime('%Y%m%d'))"
        }
    }
    
    0 讨论(0)
提交回复
热议问题