module TingYun::Agent::InstanceMethods::ContainerDataManager

Attributes

error_collector[R]
sql_sampler[R]
stats_engine[R]
transaction_sampler[R]

Public Instance Methods

container_for_endpoint(endpoint) click to toggle source
# File lib/ting_yun/agent/instance_methods/container_data_manager.rb, line 38
def container_for_endpoint(endpoint)
  case endpoint
    when :metric_data then
      @stats_engine
    # type code here
  end
end
drop_buffered_data() click to toggle source
# File lib/ting_yun/agent/instance_methods/container_data_manager.rb, line 19
def drop_buffered_data
  @stats_engine.reset!
  @transaction_sampler.reset!
  @sql_sampler.reset!
  @error_collector.reset!
end
harvest_and_send_errors() click to toggle source
# File lib/ting_yun/agent/instance_methods/container_data_manager.rb, line 64
def harvest_and_send_errors
  harvest_and_send_from_container(@error_collector.error_trace_array, :error_data)
end
harvest_and_send_exceptions() click to toggle source
# File lib/ting_yun/agent/instance_methods/container_data_manager.rb, line 68
def harvest_and_send_exceptions
  harvest_and_send_from_container(@error_collector.exception_error_array, :exception_data)
end
harvest_and_send_external_errors() click to toggle source
# File lib/ting_yun/agent/instance_methods/container_data_manager.rb, line 73
def harvest_and_send_external_errors
  harvest_and_send_from_container(@error_collector.external_error_array, :external_error_data)
end
harvest_and_send_from_container(container, endpoint) click to toggle source

Harvests data from the given container, sends it to the named endpoint on the service, and automatically merges back in upon a recoverable failure.

The given container should respond to:

#harvest!
  returns an enumerable collection of data items to be sent to the
  collector.

#reset!
  drop any stored data and reset to a clean state.

#merge!(items)
  merge the given items back into the internal buffer of the
  container, so that they may be harvested again later.
# File lib/ting_yun/agent/instance_methods/container_data_manager.rb, line 105
def harvest_and_send_from_container(container, endpoint)
  items = harvest_from_container(container, endpoint)
  send_data_to_endpoint(endpoint, items, container)
end
harvest_and_send_slowest_sql() click to toggle source
# File lib/ting_yun/agent/instance_methods/container_data_manager.rb, line 83
def harvest_and_send_slowest_sql
  harvest_and_send_from_container(@sql_sampler, :sql_trace)

end
harvest_and_send_timeslice_data() click to toggle source
# File lib/ting_yun/agent/instance_methods/container_data_manager.rb, line 60
def harvest_and_send_timeslice_data
  harvest_and_send_from_container(@stats_engine, :metric_data)
end
harvest_and_send_transaction_traces() click to toggle source
# File lib/ting_yun/agent/instance_methods/container_data_manager.rb, line 78
def harvest_and_send_transaction_traces
  harvest_and_send_from_container(@transaction_sampler, :action_trace_data)

end
harvest_from_container(container, endpoint) click to toggle source
# File lib/ting_yun/agent/instance_methods/container_data_manager.rb, line 110
def harvest_from_container(container, endpoint)
  items =[]
  begin
     if TingYun::Agent.config[:'enabled']
       items = container.harvest!
     else
       container.reset!
     end
  rescue => e
    TingYun::Agent.logger.error("Failed to harvest #{endpoint} data, resetting. Error: ", e)
    container.reset!
  end
  items
end
init_containers() click to toggle source
# File lib/ting_yun/agent/instance_methods/container_data_manager.rb, line 31
def init_containers
  @stats_engine = TingYun::Agent::Collector::StatsEngine.new
  @error_collector = TingYun::Agent::Collector::ErrorCollector.new
    @transaction_sampler = TingYun::Agent::Collector::TransactionSampler.new
  @sql_sampler = TingYun::Agent::Collector::SqlSampler.new
end
reset_objects_with_locks() click to toggle source
# File lib/ting_yun/agent/instance_methods/container_data_manager.rb, line 26
def reset_objects_with_locks
  init_containers
end
send_data_to_endpoint(endpoint, items, container) click to toggle source
# File lib/ting_yun/agent/instance_methods/container_data_manager.rb, line 144
def send_data_to_endpoint(endpoint, items, container)
  TingYun::Agent.logger.info("Sending #{items.size} items to #{endpoint}")
  begin
    @service.send(endpoint, items)
  rescue => e
    TingYun::Agent.logger.info("Unable to send #{endpoint} data, will try again later. Error: ", e)
    # container.merge!(items)
    raise
  ensure
    items = nil #  to GC
  end
end
send_data_to_endpointV2(endpoint, items, container) click to toggle source
# File lib/ting_yun/agent/instance_methods/container_data_manager.rb, line 125
def send_data_to_endpointV2(endpoint, items, container)
  TingYun::Agent.logger.info("Sending #{items.size} items to #{endpoint}")
  begin
    if container.respond_to?(:harvest_base_quantile_hash!)
      @service.send(endpoint, items, container.harvest_base_quantile_hash!)
    else
      @service.send(endpoint, items)
    end
  rescue => e
    TingYun::Agent.logger.info("Unable to send #{endpoint} data, will try again later. Error: ", e)
    # container.merge!(items)
    raise
  ensure
    items = nil #  to GC
  end


end
transmit_data() click to toggle source
# File lib/ting_yun/agent/instance_methods/container_data_manager.rb, line 46
def transmit_data
  ::TingYun::Agent.logger.debug('Sending data to Ting Yun Service')

  @events.notify(:middleware_harvest)
  @service.session do # use http keep-alive
    # harvest_and_send_errors
    # harvest_and_send_external_errors
    # harvest_and_send_exceptions
    # harvest_and_send_timeslice_data
    harvest_and_send_transaction_traces
    # harvest_and_send_slowest_sql
  end
end