Created
October 9, 2020 09:40
-
-
Save thomaspeitz/fdc1f0329093d33f3c4aa5dad92298c2 to your computer and use it in GitHub Desktop.
Influx-to-timestream
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'influxdb' | |
require 'aws-sdk-timestreamwrite' | |
client = Aws::TimestreamWrite::Client.new( | |
region: 'eu-west-1', | |
) | |
database = 'site_development' | |
influxdb = InfluxDB::Client.new(to-be-filled) | |
test = influxdb.query 'select * from your-measurement where time > \'2020-10-08T04:24:00Z\' limit 100' | |
test[0]['values'].each do |v| | |
time = Time.parse(v['time']).to_i.to_s | |
value = v['some-data'].to_s | |
puts Time.parse(v['time']) | |
puts value | |
begin | |
resp = client.write_records({ | |
database_name: "influx-migration-test", # required | |
table_name: "table-name", # required | |
records: [ # required | |
{ | |
dimensions: [ | |
{ | |
name: "stock", # required | |
value: "some-stock", # required | |
}, | |
], | |
measure_name: "some-measurement", | |
measure_value: value, | |
time: time, | |
time_unit: "SECONDS", # accepts MILLISECONDS, SECONDS, MICROSECONDS, NANOSECONDS | |
}, | |
], | |
}) | |
rescue Aws::TimestreamWrite::Errors::RejectedRecordsException => e | |
puts e.rejected_records | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment