【问题标题】:Using an id of a table for sql_last_value in logstash?在logstash中使用表的id作为sql_last_value?
【发布时间】:2017-03-15 16:26:06
【问题描述】:

我在jdbc 插件的logstash 输入中有一个这样的MySQL 语句。

statement => "SELECT * from TEST where id > :sql_last_value"

我的表没有任何 datedatetime 这样的字段。所以我正在尝试更新索引,通过使用scheduler 逐分钟检查是否有任何新行已添加到表中。

我应该只能更新新记录,而不是从现有记录更新现有值更改。所以要做到这一点,我有这种logstash 输入:

input {
    jdbc {
        jdbc_connection_string => "jdbc:mysql://myhostmachine:3306/mydb" 
        jdbc_user => "root"
        jdbc_password => "root"
        jdbc_validate_connection => true
        jdbc_driver_library => "/mypath/mysql-connector-java-5.1.39-bin.jar"
        jdbc_driver_class => "com.mysql.jdbc.Driver"
        jdbc_paging_enabled => "true"
        jdbc_page_size => "50000"
        schedule => "* * * * *"
        statement => "SELECT * from mytable where id > :sql_last_value"
        use_column_value => true
        tracking_column => id
        last_run_metadata_path => "/path/.logstash_jdbc_last_run"
        clean_run => true
    }
}

因此,每当我创建索引并运行此 logstash 文件以上传文档时,它根本不会被上传。文档计数显示为零。我确保在运行logstash conf 文件之前删除了.logstash_jdbc_last_run

logstash 控制台输出的一部分:

[2016-11-02T16:33:00,294][INFO][logstash.inputs.jdbc] (0.002000s) SELECT count(*) AS count FROM (SELECT * from TEST where id > '2016-11-02 11:02:00') AS t1 LIMIT 1

这会继续检查是否正确,但它不会得到记录。它是如何工作的?

我错过了什么吗?任何帮助都将不胜感激。

【问题讨论】:

  • 您是否尝试在您的jdbc 输入配置中添加clean_run => true?用于与 ID 字段比较的值是日期是不正常的2016-11-02 11:02:00
  • @Val 我也试过了,结果还是一样。
  • clean_run 所做的是删除.logstash_jdbc_last_run 文件。也许尝试同时指定tracking_column_type => "numeric",即使它是默认值。
  • 也许还可以使用您的最新配置更新您的问题...
  • 和我上面描述的一样:tracking_column_type => "numeric" 这是一个无证设置

标签: elasticsearch jdbc logstash logstash-configuration elasticsearch-5


【解决方案1】:

你需要像这样修改你的logstash配置:

jdbc { 
  jdbc_connection_string => "jdbc:mysql://myhostmachine:3306/mydb" 
  jdbc_user => "root" 
  jdbc_password => "root" 
  jdbc_validate_connection => true 
  jdbc_driver_library => "/mypath/mysql-connector-java-5.1.39-bin.jar" 
  jdbc_driver_class => "com.mysql.jdbc.Driver" 
  jdbc_paging_enabled => "true" 
  jdbc_page_size => "50000" 
  schedule => "* * * * *" 
  statement => "SELECT * from TEST where id > :sql_last_value" 
  use_column_value => true 
  tracking_column => "id" 
  tracking_column_type => "numeric" 
  clean_run => true 
  last_run_metadata_path => "/mypath/.logstash_jdbc_last_run" 
}

最后五个设置对您的情况很重要。还要确保删除 .logstash_jdbc_last_run 文件,即使 clean_run => true 这样做了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-14
    • 2020-04-19
    • 1970-01-01
    • 1970-01-01
    • 2023-03-06
    • 1970-01-01
    • 2016-10-06
    • 1970-01-01
    相关资源
    最近更新 更多