Skip to content

Instantly share code, notes, and snippets.

@thomaspeitz
Created October 9, 2020 09:40
Show Gist options
  • Save thomaspeitz/fdc1f0329093d33f3c4aa5dad92298c2 to your computer and use it in GitHub Desktop.
Save thomaspeitz/fdc1f0329093d33f3c4aa5dad92298c2 to your computer and use it in GitHub Desktop.
Influx-to-timestream
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