-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example from README wrong about time-precision? #219
Comments
Also, the only way I can get InfluxDB to accept nanoseconds are by using Here is my test: require 'influxdb'
client = InfluxDB::Client.new(influxdb_config['database'],
url: influxdb_config['url'],
username: influxdb_config['username'],
password: influxdb_config['password'],
async: false,
time_precision: 'ns',
)
database_name = "rails_test_#{Time.now.to_i}"
client.write_point(database_name, {
values: {value: 1},
tags: {type: 'time_now_utc'},
timestamp: (Time.now.utc.to_r * 10**6).to_i,
})
# => #<Net::HTTPNoContent 204 No Content readbody=true>
client.write_point(database_name, {
values: {value: 1},
tags: {type: 'time_now'},
timestamp: (Time.now.to_r * 10**6).to_i,
})
# => #<Net::HTTPNoContent 204 No Content readbody=true>
client.write_point(database_name, {
values: {value: 1},
tags: {type: 'process'},
timestamp: Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond),
})
# => #<Net::HTTPNoContent 204 No Content readbody=true>
time = Time.now
client.write_point(database_name, {
values: {value: 1},
tags: {type: 'time_nsec'},
timestamp: "#{time.to_i}#{time.nsec}".to_i,
})
# => #<Net::HTTPNoContent 204 No Content readbody=true>
pp client.query "SELECT * FROM #{database_name}"
# => [{"name"=>"rails_test_1531100259",
# "tags"=>nil,
# "values"=>
# [{"time"=>"1970-01-12T13:57:09.938726Z", "type"=>"process", "value"=>1},
# {"time"=>"1970-01-18T17:18:20.299806123Z", "type"=>"time_now_utc", "value"=>1},
# {"time"=>"1970-01-18T17:18:20.304718964Z", "type"=>"time_now", "value"=>1},
# {"time"=>"2018-07-09T01:38:36.56181Z", "type"=>"time_nsec", "value"=>1}]}] |
Interesting. Could you post details about your OS and Ruby build? |
Sure, I am on
Please tell me if anything else is relevant. |
From a Linux machine running Gentoo, with Ruby
I see the same:
|
They are both connected to the same InfluxDB server and they are connecting through http, and they are both using the gem version The InfluxDB is running version 1.5.4 with the docker-image version: "3"
services:
influxdb:
image: influxdb:1.5.4-alpine
volumes:
- /root/influxdb-data:/var/lib/influxdb
environment:
- INFLUXDB_DB=rails-production |
Sorry for the delayed response, I can reproduce this on my machine as well:
Looking at
The FreeBSD version of So, the sample in the readme is clearly wrong. Thanks for reporting this. I will clean it up later when I'm back home. |
@dmke No worries about the "delay", I went to bed and had a response when I woke up, so thanks! 👍 Any input is very appreciated. I see different results based on whether or not This is my current script: require 'rbconfig'
puts [RbConfig::CONFIG['MAJOR'], RbConfig::CONFIG['MINOR'], RbConfig::CONFIG['TEENY']].join('.')
puts RbConfig::CONFIG['configure_args']
influxdb_config = Rails.application.config_for(Rails.env.development? || Rails.env.test? ? :influxdb_local : :influxdb)
InfluxDB::Client.new(influxdb_config['database'],
url: influxdb_config['url'],
username: influxdb_config['username'],
password: influxdb_config['password'],
async: true,
time_precision: 'ms',
)
database_name = "rails_test_#{Time.now.to_i}"
Rails.configuration.influxdb_client.write_point(database_name, {
values: {value: 1},
tags: {type: 'time_now_to_r_utc'},
timestamp: (Time.now.utc.to_r * 1000).to_i,
})
Rails.configuration.influxdb_client.write_point(database_name, {
values: {value: 1},
tags: {type: 'time_to_r_now'},
timestamp: (Time.now.to_r * 1000).to_i,
})
Rails.configuration.influxdb_client.write_point(database_name, {
values: {value: 1},
tags: {type: 'time_to_r_now_with_precision'},
timestamp: (Time.now.to_r * 1000).to_i,
}, 'ms')
Rails.configuration.influxdb_client.write_point(database_name, {
values: {value: 1},
tags: {type: 'time_to_f_now'},
timestamp: (Time.now.to_f * 1000).to_i,
})
Rails.configuration.influxdb_client.write_point(database_name, {
values: {value: 1},
tags: {type: 'time_to_f_now_with_precision'},
timestamp: (Time.now.to_f * 1000).to_i,
}, 'ms')
Rails.configuration.influxdb_client.write_point(database_name, {
values: {value: 1},
tags: {type: 'process'},
timestamp: Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond),
})
Rails.configuration.influxdb_client.write_point(database_name, {
values: {value: 1},
tags: {type: 'process_with_precision'},
timestamp: Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond),
}, 'ms')
time = Time.now
Rails.configuration.influxdb_client.write_point(database_name, {
values: {value: 1},
tags: {type: 'time_nsec'},
timestamp: "#{time.to_i}#{time.nsec}".to_i,
})
sleep(10)
pp Rails.configuration.influxdb_client.query "SELECT * FROM #{database_name}" And the output is this:
Sorry if I have misunderstood the documentation. |
It is actually Regarding
That's because you're using |
On my system, the two examples provides different output, is that on purpose?
And running it:
The text was updated successfully, but these errors were encountered: