Class: NetuitiveRubyApi::DataManager
- Inherits:
-
Object
- Object
- NetuitiveRubyApi::DataManager
- Defined in:
- lib/netuitive_ruby_api/data_manager.rb
Instance Attribute Summary collapse
-
#data_cache ⇒ Object
Returns the value of attribute data_cache.
-
#event_cache_enabled ⇒ Object
Returns the value of attribute event_cache_enabled.
-
#event_cache_interval ⇒ Object
Returns the value of attribute event_cache_interval.
-
#event_cache_size ⇒ Object
Returns the value of attribute event_cache_size.
-
#netuitived_server ⇒ Object
Returns the value of attribute netuitived_server.
-
#sample_cache_enabled ⇒ Object
Returns the value of attribute sample_cache_enabled.
-
#sample_cache_interval ⇒ Object
Returns the value of attribute sample_cache_interval.
-
#sample_cache_size ⇒ Object
Returns the value of attribute sample_cache_size.
Instance Method Summary collapse
- #add_counter_sample(metric_id, val) ⇒ Object
- #add_sample(metric_id, val) ⇒ Object
- #aggregate_counter_metric(metric_id, val) ⇒ Object
- #aggregate_metric(metric_id, val) ⇒ Object
- #event(message, timestamp, title, level, source, type, tags) ⇒ Object
- #event_cache_addition ⇒ Object
- #exception_event(exception, klass, tags) ⇒ Object
- #flush_events ⇒ Object
- #flush_samples ⇒ Object
- #sample_cache_addition ⇒ Object
- #server_interaction ⇒ Object
Instance Attribute Details
#data_cache ⇒ Object
Returns the value of attribute data_cache.
3 4 5 |
# File 'lib/netuitive_ruby_api/data_manager.rb', line 3 def data_cache @data_cache end |
#event_cache_enabled ⇒ Object
Returns the value of attribute event_cache_enabled.
7 8 9 |
# File 'lib/netuitive_ruby_api/data_manager.rb', line 7 def event_cache_enabled @event_cache_enabled end |
#event_cache_interval ⇒ Object
Returns the value of attribute event_cache_interval.
9 10 11 |
# File 'lib/netuitive_ruby_api/data_manager.rb', line 9 def event_cache_interval @event_cache_interval end |
#event_cache_size ⇒ Object
Returns the value of attribute event_cache_size.
8 9 10 |
# File 'lib/netuitive_ruby_api/data_manager.rb', line 8 def event_cache_size @event_cache_size end |
#netuitived_server ⇒ Object
Returns the value of attribute netuitived_server.
10 11 12 |
# File 'lib/netuitive_ruby_api/data_manager.rb', line 10 def netuitived_server @netuitived_server end |
#sample_cache_enabled ⇒ Object
Returns the value of attribute sample_cache_enabled.
4 5 6 |
# File 'lib/netuitive_ruby_api/data_manager.rb', line 4 def sample_cache_enabled @sample_cache_enabled end |
#sample_cache_interval ⇒ Object
Returns the value of attribute sample_cache_interval.
6 7 8 |
# File 'lib/netuitive_ruby_api/data_manager.rb', line 6 def sample_cache_interval @sample_cache_interval end |
#sample_cache_size ⇒ Object
Returns the value of attribute sample_cache_size.
5 6 7 |
# File 'lib/netuitive_ruby_api/data_manager.rb', line 5 def sample_cache_size @sample_cache_size end |
Instance Method Details
#add_counter_sample(metric_id, val) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/netuitive_ruby_api/data_manager.rb', line 21 def add_counter_sample(metric_id, val) if @sample_cache_enabled NetuitiveRubyApi::NetuitiveLogger.log.debug "adding sample to cache: #{metric_id}" sample_cache_addition { data_cache.add_counter_sample(metric_id: metric_id, val: val) } else server_interaction { netuitived_server.addCounterSample(metric_id, val) } end end |
#add_sample(metric_id, val) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/netuitive_ruby_api/data_manager.rb', line 12 def add_sample(metric_id, val) if @sample_cache_enabled NetuitiveRubyApi::NetuitiveLogger.log.debug "adding sample to cache: #{metric_id}" sample_cache_addition { data_cache.add_sample(metric_id: metric_id, val: val) } else server_interaction { netuitived_server.addSample(metric_id, val) } end end |
#aggregate_counter_metric(metric_id, val) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/netuitive_ruby_api/data_manager.rb', line 39 def aggregate_counter_metric(metric_id, val) if @sample_cache_enabled NetuitiveRubyApi::NetuitiveLogger.log.debug "adding sample to cache: #{metric_id}" sample_cache_addition { data_cache.add_aggregate_counter_metric(metric_id: metric_id, val: val) } else server_interaction { netuitived_server.aggregateCounterMetric(metric_id, val) } end end |
#aggregate_metric(metric_id, val) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/netuitive_ruby_api/data_manager.rb', line 30 def aggregate_metric(metric_id, val) if @sample_cache_enabled NetuitiveRubyApi::NetuitiveLogger.log.debug "adding sample to cache: #{metric_id}" sample_cache_addition { data_cache.add_aggregate_metric(metric_id: metric_id, val: val) } else server_interaction { netuitived_server.aggregateMetric(metric_id, val) } end end |
#event(message, timestamp, title, level, source, type, tags) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/netuitive_ruby_api/data_manager.rb', line 48 def event(, , title, level, source, type, ) if @event_cache_enabled NetuitiveRubyApi::NetuitiveLogger.log.debug "adding event to cache: #{message}" event_cache_addition do data_cache.add_event(message: , timestamp: , title: title, level: level, source: source, type: type, tags: ) end else server_interaction { netuitived_server.event(, , title, level, source, type, ) } end end |
#event_cache_addition ⇒ Object
143 144 145 146 |
# File 'lib/netuitive_ruby_api/data_manager.rb', line 143 def event_cache_addition NetuitiveRubyAPI.check_restart flush_events if yield >= @event_cache_size end |
#exception_event(exception, klass, tags) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/netuitive_ruby_api/data_manager.rb', line 65 def exception_event(exception, klass, ) NetuitiveRubyApi::ErrorLogger.guard('error during exception_event') do hash = { message: exception. } hash[:backtrace] = exception.backtrace.join("\n\t") if (defined? exception.backtrace) && !exception.backtrace.nil? if @event_cache_enabled NetuitiveRubyApi::NetuitiveLogger.log.debug "adding exception event to cache: #{hash[:message]}" event_cache_addition do data_cache.add_exception_event(exception: hash, klass: klass, tags: ) end else server_interaction { netuitived_server.exceptionEvent(hash, klass, ) } end end end |
#flush_events ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/netuitive_ruby_api/data_manager.rb', line 116 def flush_events NetuitiveRubyApi::ErrorLogger.guard('error during flush_events') do event_cache = data_cache.clear_event_cache num = event_cache[:events].size + event_cache[:exception_events].size NetuitiveRubyApi::NetuitiveLogger.log.info "sending #{num} events" if num > 0 threads = [] unless event_cache[:events].empty? threads << server_interaction do NetuitiveRubyApi::NetuitiveLogger.log.debug "sending events: #{event_cache[:events]} " netuitived_server.add_events(event_cache[:events]) end end unless event_cache[:exception_events].empty? threads << server_interaction do NetuitiveRubyApi::NetuitiveLogger.log.debug "sending exception_events: #{event_cache[:exception_events]} " netuitived_server.add_exception_events(event_cache[:exception_events]) end end threads end end |
#flush_samples ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/netuitive_ruby_api/data_manager.rb', line 82 def flush_samples NetuitiveRubyApi::ErrorLogger.guard('error during flush_samples') do sample = data_cache.clear_sample_cache num = sample[:samples].size + sample[:counter_samples].size + sample[:aggregate_metrics].size + sample[:aggregate_counter_metrics].size NetuitiveRubyApi::NetuitiveLogger.log.info "sending #{num} samples" if num > 0 threads = [] unless sample[:samples].empty? threads << server_interaction do NetuitiveRubyApi::NetuitiveLogger.log.debug "sending samples: #{sample[:samples]} " netuitived_server.add_samples sample[:samples] end end unless sample[:counter_samples].empty? threads << server_interaction do NetuitiveRubyApi::NetuitiveLogger.log.debug "sending counter_samples: #{sample[:counter_samples]} " netuitived_server.add_counter_samples sample[:counter_samples] end end unless sample[:aggregate_metrics].empty? threads << server_interaction do NetuitiveRubyApi::NetuitiveLogger.log.debug "sending aggregate_metrics: #{sample[:aggregate_metrics]} " netuitived_server.add_aggregate_metrics sample[:aggregate_metrics] end end unless sample[:aggregate_counter_metrics].empty? threads << server_interaction do NetuitiveRubyApi::NetuitiveLogger.log.debug "sending aggregate_counter_metrics: #{sample[:aggregate_counter_metrics]} " netuitived_server.add_aggregate_counter_metrics sample[:aggregate_counter_metrics] end end threads end end |
#sample_cache_addition ⇒ Object
138 139 140 141 |
# File 'lib/netuitive_ruby_api/data_manager.rb', line 138 def sample_cache_addition NetuitiveRubyAPI.check_restart flush_samples if yield >= @sample_cache_size end |
#server_interaction ⇒ Object
148 149 150 151 152 |
# File 'lib/netuitive_ruby_api/data_manager.rb', line 148 def server_interaction Thread.new do NetuitiveRubyApi::ErrorLogger.guard('error during server interaction') { yield } end end |