问题
I'm having a MySQL statement as such within my jdbc
plugin in logstash
input.
statement => "SELECT * from TEST where id > :sql_last_value"
My table doesn't have any date
or datetime
field as such. So I'm trying to update the index, by checking minute by minute using a scheduler
, whether any new rows have been added to the table.
I should only be able to update the new records, rather than updating the existing value changes from an existing record. So to do this I'm having this kinda of a logstash
input:
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
}
}
So whenever I create an index and run this logstash
file in order to upload the docs, it doesn't get uploaded at all. The docs count shows as zero. I made sure that I deleted the .logstash_jdbc_last_run
before I ran the logstash
conf file.
Part of logstash console output:
[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') ASt1
LIMIT 1
and this keeps on going by checking minute by minute which is correct but then it doesn't get the records. How does it work?
Am I missing something? Any help could be appreciated.
回答1:
You need to modify your logstash configuration like this:
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"
}
The last five settings are important in your case. Also make sure to delete the .logstash_jdbc_last_run
file even though clean_run => true
does it.
来源:https://stackoverflow.com/questions/40378580/using-an-id-of-a-table-for-sql-last-value-in-logstash