为什么Logstash在~/.Logstash\u jdbc\u last\u run中放置了错误的时区?

为什么Logstash在~/.Logstash\u jdbc\u last\u run中放置了错误的时区?,logstash,logstash-configuration,logstash-jdbc,Logstash,Logstash Configuration,Logstash Jdbc,日志存储5.2.1 以下配置正常,部分更新正常。我只是误解了结果以及Logstash是如何使用时区的。 时区转换。SQL不允许在时间戳字段中使用时区数据。此插件将自动将SQL时间戳字段转换为日志存储时间戳,以ISO8601格式的相对UTC时间表示。 使用此设置将手动分配指定的时区偏移,而不是使用本地计算机的时区设置。您必须使用标准时区,例如欧洲/罗马 我想在Logstash的帮助下将一些数据从PostgreSQL索引到Elasticseach。部分更新应该可以正常工作 但是在我的例子中,Lo

日志存储5.2.1

以下配置正常,部分更新正常。我只是误解了结果以及Logstash是如何使用时区的。

时区转换。SQL不允许在时间戳字段中使用时区数据。此插件将自动将SQL时间戳字段转换为日志存储时间戳,以ISO8601格式的相对UTC时间表示。 使用此设置将手动分配指定的时区偏移,而不是使用本地计算机的时区设置。您必须使用标准时区,例如欧洲/罗马


我想在Logstash的帮助下将一些数据从PostgreSQL索引到Elasticseach。部分更新应该可以正常工作

但是在我的例子中,Logstash在
~/.Logstash\u jdbc\u last\u run
中放置了错误的时区

$cat ~/.logstash_jdbc_last_run 
--- 2017-03-08 09:29:00.259000000 Z
我的电脑/服务器时间:

$date
mer  8 mar 2017, 10.29.31, CET
$cat /etc/timezone 
Europe/Rome
我的日志存储配置:

input {
  jdbc {
    # Postgres jdbc connection string to our database, mydb
    jdbc_connection_string => "jdbc:postgresql://localhost:5432/postgres"
    # The user we wish to execute our statement as
    jdbc_user => "logstash"
    jdbc_password => "logstashpass"
    # The path to our downloaded jdbc driver
    jdbc_driver_library => "/home/trex/Development/ship_to_elasticsearch/software/postgresql-42.0.0.jar"
    # The name of the driver class for Postgresql
    jdbc_driver_class => "org.postgresql.Driver"
    jdbc_default_timezone => "Europe/Rome"
    # our query
    statement => "SELECT * FROM contacts WHERE timestamp > :sql_last_value"
    # every 1 min
    schedule => "*/1 * * * *"
  }
}
output {
  stdout { codec => json_lines }
  elasticsearch {
    hosts => [ "localhost:9200" ]
    index => "database.%{+yyyy.MM.dd.HH}"
  }
}
没有
jdbc\u default\u时区
时区也是错误的

我的PostgeSQL数据:

postgres=# select * from "contacts";                                                                                               uid |         timestamp          |          email          | first_name | last_name
-----+----------------------------+-------------------------+------------+------------
   1 | 2017-03-07 18:09:25.358684 | jim@example.com         | Jim        | Smith
   2 | 2017-03-07 18:09:25.3756   |                         | John       | Smith
   3 | 2017-03-07 18:09:25.384053 | carol@example.com       | Carol      | Smith
   4 | 2017-03-07 18:09:25.869833 | sam@example.com         | Sam        |
   5 | 2017-03-08 10:04:26.39423  | trex@example.com        | T          | Rex
DB数据的导入方式如下:

INSERT INTO contacts(timestamp, email, first_name, last_name) VALUES(current_timestamp, 'sam@example.com', 'Sam', null);

为什么Logstash在
~/.Logstash\u jdbc\u last\u run中放置了错误的时区?如何修复它?

2017-03-08 09:29:00.259000000 Z
表示UTC
时区,它是正确的。

它默认为UTC时间。如果要将时间戳存储在不同的时区,可以通过添加如下过滤器来转换时间戳:

filter {
    mutate {
    add_field => {
        # Create a new field with string value of the UTC event date
        "timestamp_extract" => "%{@timestamp}"
    }
    }

    date {
    # Parse UTC string value and convert it to my timezone into a new field
    match => [ "timestamp_extract", "yyyy-MM-dd HH:mm:ss Z" ]
    timezone => "Europe/Rome"
    locale => "en"
    remove_field => [ "timestamp_extract" ]
    target => "timestamp_europe"
    }
}
这将转换时区,首先将时间戳提取到时间戳提取字段,然后将其转换为欧洲/罗马时区。并且新转换的时间戳被放入timestamp_europe字段中


希望它现在更清晰

好的,那么为什么我要连续导入第5个DB记录?请看更新问题。对不起,我之前的评论有误导性。我在Logstash中配置了
jdbc\u default\u timezone=>“Europe/Rome”
。所以,我必须有罗马时区,不是吗?
时区转换。SQL不允许在时间戳字段中使用时区数据。此插件将自动将SQL时间戳字段转换为日志存储时间戳,采用ISO8601格式的相对UTC时间。
因此,导入后的时区始终为UTC,此设置仅用于转换OK,那么我需要配置什么来获得正确的部分更新?