class InfluxReporter::InfluxDBClient

@api private

Attributes

client[R]
config[R]
state[R]

Public Class Methods

new(config) click to toggle source

@param config [InfluxReporter::Configuration]

# File lib/influx_reporter/influx_db_client.rb, line 15
def initialize(config)
  @config = config
  @client = InfluxDB::Client.new config.database, config.influx_db.merge(time_precision: 'ns')
  @state = ClientState.new config
end

Public Instance Methods

post(resource, data) click to toggle source
# File lib/influx_reporter/influx_db_client.rb, line 23
def post(resource, data)
  debug "POST #{resource[:url]}"

  unless state.should_try?
    info 'Temporarily skipping sending to InfluxReporter due to previous failure.'
    return
  end

  begin
    data = [data] unless data.is_a?(Array)
    client.write_points data, nil, nil, resource.fetch(:database, nil)
  rescue StandardError => e
    debug { e.message }
    @state.fail!
    raise
  end

  @state.success!

  true
end