diff --git a/influx_hs110_energy.rb b/influx_hs110_energy.rb index b176c4e..2dc1f74 100755 --- a/influx_hs110_energy.rb +++ b/influx_hs110_energy.rb @@ -96,7 +96,7 @@ threads << Thread.new do debug_message("Creating processing thread for plug #{plug_name}.") if options[:verbose] begin - time_start = Process.clock_gettime(Process::CLOCK_MONOTONIC) if options[:debug] + time_start = Process.clock_gettime(Process::CLOCK_MONOTONIC) plug = TpLinkSmartplugInflux::Plug.new(name: plug_name, address: config['address']) %i(debug= verbose=).each { |opt| plug.send(opt, config[opt]) } @@ -119,6 +119,7 @@ measurement_string = '' measurement_string.concat("#{measurement},") measurement_string.concat(plug.influx_line) + measurement_string.concat(",polltime=#{milliseconds_since(time_start)}") measurement_strings.push(measurement_string) diff --git a/lib/tp_link_smartplug_influx/helpers.rb b/lib/tp_link_smartplug_influx/helpers.rb index 6e943aa..2dd8508 100644 --- a/lib/tp_link_smartplug_influx/helpers.rb +++ b/lib/tp_link_smartplug_influx/helpers.rb @@ -23,6 +23,13 @@ def seconds_since(time) (Process.clock_gettime(Process::CLOCK_MONOTONIC) - time).round(2) end +# Get the number of milliseconds elapsed since the provided time. +# @param time [Float] Previous time input. +# @return [Integer] Milliseconds elapsed. +def milliseconds_since(time) + ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - time) * 1000).round +end + module TpLinkSmartplugInflux # Module containing helper methods to be included within the base class. #