Module: TingYun::Agent::InstanceMethods::ContainerDataManager
- Included in:
- TingYun::Agent::InstanceMethods
- Defined in:
- lib/ting_yun/agent/instance_methods/container_data_manager.rb
Instance Attribute Summary collapse
-
#error_collector ⇒ Object
readonly
Returns the value of attribute error_collector.
-
#sql_sampler ⇒ Object
readonly
Returns the value of attribute sql_sampler.
-
#stats_engine ⇒ Object
readonly
Returns the value of attribute stats_engine.
-
#transaction_sampler ⇒ Object
readonly
Returns the value of attribute transaction_sampler.
Instance Method Summary collapse
- #container_for_endpoint(endpoint) ⇒ Object
- #drop_buffered_data ⇒ Object
- #harvest_and_send_errors ⇒ Object
- #harvest_and_send_exceptions ⇒ Object
- #harvest_and_send_external_errors ⇒ Object
-
#harvest_and_send_from_container(container, endpoint) ⇒ Object
Harvests data from the given container, sends it to the named endpoint on the service, and automatically merges back in upon a recoverable failure.
- #harvest_and_send_slowest_sql ⇒ Object
- #harvest_and_send_timeslice_data ⇒ Object
- #harvest_and_send_transaction_traces ⇒ Object
- #harvest_from_container(container, endpoint) ⇒ Object
- #init_containers ⇒ Object
- #reset_objects_with_locks ⇒ Object
- #send_data_to_endpoint(endpoint, items, container) ⇒ Object
- #transmit_data ⇒ Object
Instance Attribute Details
#error_collector ⇒ Object (readonly)
Returns the value of attribute error_collector.
17 18 19 |
# File 'lib/ting_yun/agent/instance_methods/container_data_manager.rb', line 17 def error_collector @error_collector end |
#sql_sampler ⇒ Object (readonly)
Returns the value of attribute sql_sampler.
17 18 19 |
# File 'lib/ting_yun/agent/instance_methods/container_data_manager.rb', line 17 def sql_sampler @sql_sampler end |
#stats_engine ⇒ Object (readonly)
Returns the value of attribute stats_engine.
17 18 19 |
# File 'lib/ting_yun/agent/instance_methods/container_data_manager.rb', line 17 def stats_engine @stats_engine end |
#transaction_sampler ⇒ Object (readonly)
Returns the value of attribute transaction_sampler.
17 18 19 |
# File 'lib/ting_yun/agent/instance_methods/container_data_manager.rb', line 17 def transaction_sampler @transaction_sampler end |
Instance Method Details
#container_for_endpoint(endpoint) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/ting_yun/agent/instance_methods/container_data_manager.rb', line 39 def container_for_endpoint(endpoint) case endpoint when :metric_data then @stats_engine # type code here end end |
#drop_buffered_data ⇒ Object
20 21 22 23 24 25 |
# File 'lib/ting_yun/agent/instance_methods/container_data_manager.rb', line 20 def drop_buffered_data @stats_engine.reset! @transaction_sampler.reset! @sql_sampler.reset! @error_collector.reset! end |
#harvest_and_send_errors ⇒ Object
65 66 67 |
# File 'lib/ting_yun/agent/instance_methods/container_data_manager.rb', line 65 def harvest_and_send_errors harvest_and_send_from_container(@error_collector.error_trace_array, :error_data) end |
#harvest_and_send_exceptions ⇒ Object
69 70 71 |
# File 'lib/ting_yun/agent/instance_methods/container_data_manager.rb', line 69 def harvest_and_send_exceptions harvest_and_send_from_container(@error_collector.exception_error_array, :exception_data) end |
#harvest_and_send_external_errors ⇒ Object
74 75 76 |
# File 'lib/ting_yun/agent/instance_methods/container_data_manager.rb', line 74 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) ⇒ Object
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.
106 107 108 109 |
# File 'lib/ting_yun/agent/instance_methods/container_data_manager.rb', line 106 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 ⇒ Object
84 85 86 87 |
# File 'lib/ting_yun/agent/instance_methods/container_data_manager.rb', line 84 def harvest_and_send_slowest_sql harvest_and_send_from_container(@sql_sampler, :sql_trace) end |
#harvest_and_send_timeslice_data ⇒ Object
61 62 63 |
# File 'lib/ting_yun/agent/instance_methods/container_data_manager.rb', line 61 def harvest_and_send_timeslice_data harvest_and_send_from_container(@stats_engine, :metric_data) end |
#harvest_and_send_transaction_traces ⇒ Object
79 80 81 82 |
# File 'lib/ting_yun/agent/instance_methods/container_data_manager.rb', line 79 def harvest_and_send_transaction_traces harvest_and_send_from_container(@transaction_sampler, :action_trace_data) end |
#harvest_from_container(container, endpoint) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/ting_yun/agent/instance_methods/container_data_manager.rb', line 111 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 ⇒ Object
32 33 34 35 36 37 |
# File 'lib/ting_yun/agent/instance_methods/container_data_manager.rb', line 32 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 ⇒ Object
27 28 29 |
# File 'lib/ting_yun/agent/instance_methods/container_data_manager.rb', line 27 def reset_objects_with_locks init_containers end |
#send_data_to_endpoint(endpoint, items, container) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/ting_yun/agent/instance_methods/container_data_manager.rb', line 126 def send_data_to_endpoint(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 ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ting_yun/agent/instance_methods/container_data_manager.rb', line 47 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 |