netuitive_ruby_api 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/config/agent.yml CHANGED
@@ -1,7 +1,19 @@
1
1
  #all are configurable using environment variables
2
- logLocation: #absolute path of log file. leave blank for default location in the gem directory. environment variable: NETUITIVE_RUBY_LOG_LOCATION
3
- logAge: daily #Number of old log files to keep, or frequency of rotation (daily, weekly or monthly). environment variable: NETUITIVE_RUBY_LOG_AGE
4
- logSize: #Maximum logfile size in bytes (only applies when shift_age is a number). environment variable: NETUITIVE_RUBY_LOG_SIZE
5
- debugLevel: info #options (in ascending order of debugness) are: error, info, debug. environment variable: NETUITIVE_RUBY_DEBUG_LEVEL
6
- netuitivedAddr: localhost #environment variable: NETUITIVE_RUBY_NETUITIVED_ADDR
7
- netuitivedPort: 8875 #environment variable: NETUITIVE_RUBY_NETUITIVED_PORT
2
+ #log properties
3
+ logLocation: #NETUITIVE_RUBY_LOG_LOCATION absolute path of log file. leave blank for default location in the gem directory.
4
+ logAge: daily #NETUITIVE_RUBY_LOG_AGE Number of old log files to keep, or frequency of rotation (daily, weekly or monthly).
5
+ logSize: #NETUITIVE_RUBY_LOG_SIZE Maximum logfile size in bytes (only applies when shift_age is a number).
6
+ debugLevel: error #NETUITIVE_RUBY_DEBUG_LEVEL options (in ascending order of debugness) are: error, info, debug.
7
+
8
+ #netuitived connection properties
9
+ netuitivedAddr: localhost #NETUITIVE_RUBY_NETUITIVED_ADDR
10
+ netuitivedPort: 8875 #NETUITIVE_RUBY_NETUITIVED_PORT
11
+
12
+ #cache properties
13
+ #the point of the cache is to be as *small* as possible while still avoiding excessive delivery thread growth.
14
+ sampleCacheEnabled: true #NETUITIVE_RUBY_SAMPLE_CACHE_ENABLED
15
+ sampleCacheSize: 50 #NETUITIVE_RUBY_SAMPLE_CACHE_SIZE maximum number of samples to be cached before being sent to netuitived
16
+ sampleCacheInterval: 10 #NETUITIVE_RUBY_SAMPLE_CACHE_INTERVAL interval (in seconds) to send cached samples to netuitived
17
+ eventCacheEnabled: false #NETUITIVE_RUBY_EVENT_CACHE_ENABLED
18
+ eventCacheSize: 50 #NETUITIVE_RUBY_SAMPLE_CACHE_SIZE maximum number of events to be cached before being sent to netuitived
19
+ eventCacheInterval: 10 #NETUITIVE_RUBY_SAMPLE_CACHE_INTERVAL interval (in seconds) to send cached events to netuitived
@@ -3,39 +3,81 @@ require 'logger'
3
3
  require 'drb/drb'
4
4
  require 'netuitive_ruby_api/config_manager'
5
5
  require 'netuitive_ruby_api/netuitive_logger'
6
+ require 'netuitive_ruby_api/error_logger'
7
+ require 'netuitive_ruby_api/data_cache'
8
+ require 'netuitive_ruby_api/data_manager'
9
+ require 'netuitive_ruby_api/event_schedule'
10
+ require 'netuitive_ruby_api/sample_schedule'
6
11
 
7
12
  class NetuitiveRubyAPI
8
13
  class << self
9
- def setup(server)
10
- @@netuitivedServer = server
14
+ attr_accessor :data_manager
15
+ attr_accessor :netuitivedServer
16
+ attr_reader :pid
17
+ def setup
18
+ @pid = Process.pid
19
+ NetuitiveRubyApi::ConfigManager.load_config
20
+ NetuitiveRubyApi::NetuitiveLogger.setup
21
+ NetuitiveRubyApi::ConfigManager.read_config
22
+ NetuitiveRubyApi::ErrorLogger.guard('error during api setup') do
23
+ server_uri = "druby://#{NetuitiveRubyApi::ConfigManager.netuitivedAddr}:#{NetuitiveRubyApi::ConfigManager.netuitivedPort}".freeze
24
+ DRb.start_service
25
+ drb_server = DRbObject.new_with_uri(server_uri)
26
+ data_manager = NetuitiveRubyApi::DataManager.new
27
+ data_manager.data_cache = NetuitiveRubyApi::DataCache.new
28
+ data_manager.sample_cache_enabled = NetuitiveRubyApi::ConfigManager.sample_cache_enabled
29
+ data_manager.sample_cache_size = NetuitiveRubyApi::ConfigManager.sample_cache_size
30
+ data_manager.sample_cache_interval = NetuitiveRubyApi::ConfigManager.sample_cache_interval
31
+ data_manager.event_cache_enabled = NetuitiveRubyApi::ConfigManager.event_cache_enabled
32
+ data_manager.event_cache_size = NetuitiveRubyApi::ConfigManager.event_cache_size
33
+ data_manager.event_cache_interval = NetuitiveRubyApi::ConfigManager.event_cache_interval
34
+ data_manager.netuitived_server = drb_server
35
+ @netuitivedServer = drb_server
36
+ @data_manager = data_manager
37
+ NetuitiveRubyApi::SampleSchedule.stop
38
+ NetuitiveRubyApi::EventSchedule.stop
39
+ NetuitiveRubyApi::SampleSchedule.start(NetuitiveRubyApi::ConfigManager.sample_cache_interval) if NetuitiveRubyApi::ConfigManager.sample_cache_enabled
40
+ NetuitiveRubyApi::EventSchedule.start(NetuitiveRubyApi::ConfigManager.event_cache_interval) if NetuitiveRubyApi::ConfigManager.event_cache_enabled
41
+ NetuitiveRubyApi::NetuitiveLogger.log.info 'netuitive_ruby_api finished setup'
42
+ end
43
+ end
44
+
45
+ def flush_samples
46
+ @data_manager.flush_samples
47
+ end
48
+
49
+ def check_restart
50
+ NetuitiveRubyApi::NetuitiveLogger.log.debug "stored pid: #{@pid}, process pid: #{Process.pid}"
51
+ return if @pid == Process.pid
52
+ Thread.new { NetuitiveRubyAPI.setup }
11
53
  end
12
54
 
13
- def netuitivedServer
14
- @@netuitivedServer
55
+ def flush_events
56
+ @data_manager.flush_events
15
57
  end
16
58
 
17
59
  def send_metrics
18
- server_interaction { netuitivedServer.sendMetrics }
60
+ netuitivedServer.sendMetrics
19
61
  end
20
62
 
21
63
  def add_sample(metric_id, val)
22
- server_interaction { netuitivedServer.addSample(metric_id, val) }
64
+ @data_manager.add_sample(metric_id, val)
23
65
  end
24
66
 
25
67
  def add_counter_sample(metric_id, val)
26
- server_interaction { netuitivedServer.addCounterSample(metric_id, val) }
68
+ @data_manager.add_counter_sample(metric_id, val)
27
69
  end
28
70
 
29
71
  def aggregate_metric(metric_id, val)
30
- server_interaction { netuitivedServer.aggregateMetric(metric_id, val) }
72
+ @data_manager.aggregate_metric(metric_id, val)
31
73
  end
32
74
 
33
75
  def aggregate_counter_metric(metric_id, val)
34
- server_interaction { netuitivedServer.aggregateCounterMetric(metric_id, val) }
76
+ @data_manager.aggregate_counter_metric(metric_id, val)
35
77
  end
36
78
 
37
79
  def clear_metrics
38
- server_interaction { netuitivedServer.clearMetrics }
80
+ netuitivedServer.clearMetrics
39
81
  end
40
82
 
41
83
  def interval
@@ -43,36 +85,17 @@ class NetuitiveRubyAPI
43
85
  end
44
86
 
45
87
  def event(message, timestamp = Time.new, title = 'Ruby Event', level = 'Info', source = 'Ruby Agent', type = 'INFO', tags = nil)
46
- server_interaction { netuitivedServer.event(message, timestamp, title, level, source, type, tags) }
88
+ @data_manager.event(message, timestamp, title, level, source, type, tags)
47
89
  end
48
90
 
49
91
  def exception_event(exception, klass = nil, tags = nil)
50
- server_interaction do
51
- hash = { message: exception.message }
52
- hash[:backtrace] = exception.backtrace.join("\n\t") if (defined? exception.backtrace) && !exception.backtrace.nil?
53
- netuitivedServer.exceptionEvent(hash, klass, tags)
54
- end
92
+ @data_manager.exception_event(exception, klass, tags)
55
93
  end
56
94
 
57
95
  def stop_server
58
- server_interaction { netuitivedServer.stopServer }
59
- end
60
-
61
- def server_interaction
62
- Thread.new do
63
- begin
64
- yield
65
- rescue => e
66
- NetuitiveRubyApi::NetuitiveLogger.log.error "unable to connect to netuitived: message:#{e.message} backtrace:#{e.backtrace}"
67
- end
68
- end
96
+ netuitivedServer.stopServer
69
97
  end
70
98
  end
71
99
  end
72
100
 
73
- NetuitiveRubyApi::ConfigManager.load_config
74
- NetuitiveRubyApi::NetuitiveLogger.setup
75
- NetuitiveRubyApi::ConfigManager.read_config
76
- SERVER_URI = "druby://#{NetuitiveRubyApi::ConfigManager.netuitivedAddr}:#{NetuitiveRubyApi::ConfigManager.netuitivedPort}".freeze
77
- DRb.start_service
78
- NetuitiveRubyAPI.setup(DRbObject.new_with_uri(SERVER_URI))
101
+ NetuitiveRubyAPI.setup
@@ -2,10 +2,14 @@ module NetuitiveRubyApi
2
2
  class ConfigManager
3
3
  class << self
4
4
  attr_reader :netuitivedAddr
5
-
6
5
  attr_reader :netuitivedPort
7
-
8
6
  attr_reader :data
7
+ attr_reader :sample_cache_enabled
8
+ attr_reader :sample_cache_size
9
+ attr_reader :sample_cache_interval
10
+ attr_reader :event_cache_enabled
11
+ attr_reader :event_cache_size
12
+ attr_reader :event_cache_interval
9
13
 
10
14
  def property(name, var, default = nil)
11
15
  prop = ENV[var]
@@ -26,12 +30,11 @@ module NetuitiveRubyApi
26
30
  end
27
31
 
28
32
  def float_property(name, var)
29
- prop = ENV[var].nil? ? nil : ENV[var]
30
- if prop.nil? || (prop == '')
31
- data[name].to_f
32
- else
33
- prop.to_f
34
- end
33
+ property(name, var).to_f
34
+ end
35
+
36
+ def int_property(name, var)
37
+ property(name, var).to_i
35
38
  end
36
39
 
37
40
  def string_list_property(name, var)
@@ -52,6 +55,12 @@ module NetuitiveRubyApi
52
55
  end
53
56
 
54
57
  def read_config
58
+ @sample_cache_enabled = boolean_property('sampleCacheEnabled', 'NETUITIVE_RUBY_SAMPLE_CACHE_ENABLED')
59
+ @sample_cache_size = int_property('sampleCacheSize', 'NETUITIVE_RUBY_SAMPLE_CACHE_SIZE')
60
+ @sample_cache_interval = int_property('sampleCacheInterval', 'NETUITIVE_RUBY_SAMPLE_CACHE_INTERVAL')
61
+ @event_cache_enabled = boolean_property('eventCacheEnabled', 'NETUITIVE_RUBY_EVENT_CACHE_ENABLED')
62
+ @event_cache_size = int_property('eventCacheSize', 'NETUITIVE_RUBY_SAMPLE_CACHE_SIZE')
63
+ @event_cache_interval = int_property('eventCacheInterval', 'NETUITIVE_RUBY_SAMPLE_CACHE_INTERVAL')
55
64
  @netuitivedAddr = property('netuitivedAddr', 'NETUITIVE_RUBY_NETUITIVED_ADDR')
56
65
  @netuitivedPort = property('netuitivedPort', 'NETUITIVE_RUBY_NETUITIVED_PORT')
57
66
  debugLevelString = property('debugLevel', 'NETUITIVE_RUBY_DEBUG_LEVEL')
@@ -64,12 +73,18 @@ module NetuitiveRubyApi
64
73
  else
65
74
  Logger::ERROR
66
75
  end
67
- NetuitiveRubyApi::NetuitiveLogger.log.info "port: #{@netuitivedPort}"
68
- NetuitiveRubyApi::NetuitiveLogger.log.info "addr: #{@netuitivedAddr}"
76
+ NetuitiveRubyApi::NetuitiveLogger.log.info "netuitived port: #{@netuitivedPort}"
77
+ NetuitiveRubyApi::NetuitiveLogger.log.info "netuitived addr: #{@netuitivedAddr}"
69
78
  NetuitiveRubyApi::NetuitiveLogger.log.debug "read config file. Results:
70
79
  netuitivedAddr: #{@netuitivedAddr}
71
80
  netuitivedPort: #{@netuitivedPort}
72
- debugLevel: #{debugLevelString}"
81
+ debugLevel: #{debugLevelString}
82
+ sample_cache_enabled: #{@sample_cache_enabled}
83
+ sample_cache_size: #{@sample_cache_size}
84
+ sample_cache_interval: #{@sample_cache_interval}
85
+ event_cache_enabled: #{@event_cache_enabled}
86
+ event_cache_size: #{@event_cache_size}
87
+ event_cache_interval: #{@event_cache_interval}"
73
88
  end
74
89
  end
75
90
  end
@@ -0,0 +1,104 @@
1
+ module NetuitiveRubyApi
2
+ class DataCache
3
+ def initialize
4
+ @sample_count_mutex = Mutex.new
5
+ @event_count_mutex = Mutex.new
6
+ reset_samples
7
+ reset_events
8
+ end
9
+
10
+ def sample_added
11
+ @sample_count += 1
12
+ end
13
+
14
+ def event_added
15
+ @event_count += 1
16
+ end
17
+
18
+ def add_sample(value)
19
+ @sample_count_mutex.synchronize do
20
+ @samples.push(value)
21
+ sample_added
22
+ end
23
+ end
24
+
25
+ def add_counter_sample(value)
26
+ @sample_count_mutex.synchronize do
27
+ @counter_samples.push(value)
28
+ sample_added
29
+ end
30
+ end
31
+
32
+ def add_aggregate_metric(value)
33
+ @sample_count_mutex.synchronize do
34
+ @aggregate_metrics.push(value)
35
+ sample_added
36
+ end
37
+ end
38
+
39
+ def add_aggregate_counter_metric(value)
40
+ @sample_count_mutex.synchronize do
41
+ @aggregate_counter_metrics.push(value)
42
+ sample_added
43
+ end
44
+ end
45
+
46
+ def add_event(value)
47
+ @event_count_mutex.synchronize do
48
+ @events.push(value)
49
+ event_added
50
+ end
51
+ end
52
+
53
+ def add_exception_event(value)
54
+ @event_count_mutex.synchronize do
55
+ @exception_events.push(value)
56
+ event_added
57
+ end
58
+ end
59
+
60
+ def clear_sample_cache
61
+ NetuitiveRubyApi::ErrorLogger.guard('error during clear_sample_cache') do
62
+ @sample_count_mutex.synchronize do
63
+ NetuitiveRubyApi::NetuitiveLogger.log.debug 'clearing sample cache'
64
+ ret = {
65
+ samples: @samples.dup,
66
+ counter_samples: @counter_samples.dup,
67
+ aggregate_metrics: @aggregate_metrics.dup,
68
+ aggregate_counter_metrics: @aggregate_counter_metrics.dup
69
+ }
70
+ reset_samples
71
+ ret
72
+ end
73
+ end
74
+ end
75
+
76
+ def clear_event_cache
77
+ NetuitiveRubyApi::ErrorLogger.guard('error during clear_event_cache') do
78
+ @event_count_mutex.synchronize do
79
+ NetuitiveRubyApi::NetuitiveLogger.log.debug 'clearing event cache'
80
+ ret = {
81
+ events: @events.dup,
82
+ exception_events: @exception_events.dup
83
+ }
84
+ reset_events
85
+ ret
86
+ end
87
+ end
88
+ end
89
+
90
+ def reset_samples
91
+ @samples = []
92
+ @counter_samples = []
93
+ @aggregate_metrics = []
94
+ @aggregate_counter_metrics = []
95
+ @sample_count = 0
96
+ end
97
+
98
+ def reset_events
99
+ @events = []
100
+ @exception_events = []
101
+ @event_count = 0
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,142 @@
1
+ module NetuitiveRubyApi
2
+ class DataManager
3
+ attr_accessor :data_cache
4
+ attr_accessor :sample_cache_enabled
5
+ attr_accessor :sample_cache_size
6
+ attr_accessor :sample_cache_interval
7
+ attr_accessor :event_cache_enabled
8
+ attr_accessor :event_cache_size
9
+ attr_accessor :event_cache_interval
10
+ attr_accessor :netuitived_server
11
+
12
+ def add_sample(metric_id, val)
13
+ if @sample_cache_enabled
14
+ NetuitiveRubyApi::NetuitiveLogger.log.debug "adding sample to cache: #{metric_id}"
15
+ sample_cache_addition { data_cache.add_sample(metric_id: metric_id, val: val) }
16
+ else
17
+ server_interaction { netuitived_server.addSample(metric_id, val) }
18
+ end
19
+ end
20
+
21
+ def add_counter_sample(metric_id, val)
22
+ if @sample_cache_enabled
23
+ NetuitiveRubyApi::NetuitiveLogger.log.debug "adding sample to cache: #{metric_id}"
24
+ sample_cache_addition { data_cache.add_counter_sample(metric_id: metric_id, val: val) }
25
+ else
26
+ server_interaction { netuitived_server.addCounterSample(metric_id, val) }
27
+ end
28
+ end
29
+
30
+ def aggregate_metric(metric_id, val)
31
+ if @sample_cache_enabled
32
+ NetuitiveRubyApi::NetuitiveLogger.log.debug "adding sample to cache: #{metric_id}"
33
+ sample_cache_addition { data_cache.add_aggregate_metric(metric_id: metric_id, val: val) }
34
+ else
35
+ server_interaction { netuitived_server.aggregateMetric(metric_id, val) }
36
+ end
37
+ end
38
+
39
+ def aggregate_counter_metric(metric_id, val)
40
+ if @sample_cache_enabled
41
+ NetuitiveRubyApi::NetuitiveLogger.log.debug "adding sample to cache: #{metric_id}"
42
+ sample_cache_addition { data_cache.add_aggregate_counter_metric(metric_id: metric_id, val: val) }
43
+ else
44
+ server_interaction { netuitived_server.aggregateCounterMetric(metric_id, val) }
45
+ end
46
+ end
47
+
48
+ def event(message, timestamp, title, level, source, type, tags)
49
+ if @event_cache_enabled
50
+ NetuitiveRubyApi::NetuitiveLogger.log.debug "adding event to cache: #{message}"
51
+ event_cache_addition do
52
+ data_cache.add_event(message: message,
53
+ timestamp: timestamp,
54
+ title: title,
55
+ level: level,
56
+ source: source,
57
+ type: type,
58
+ tags: tags)
59
+ end
60
+ else
61
+ server_interaction { netuitived_server.event(message, timestamp, title, level, source, type, tags) }
62
+ end
63
+ end
64
+
65
+ def exception_event(exception, klass, tags)
66
+ NetuitiveRubyApi::ErrorLogger.guard('error during exception_event') do
67
+ hash = { message: exception.message }
68
+ hash[:backtrace] = exception.backtrace.join("\n\t") if (defined? exception.backtrace) && !exception.backtrace.nil?
69
+ if @event_cache_enabled
70
+ NetuitiveRubyApi::NetuitiveLogger.log.debug "adding exception event to cache: #{hash[:message]}"
71
+ event_cache_addition do
72
+ data_cache.add_exception_event(exception: hash,
73
+ klass: klass,
74
+ tags: tags)
75
+ end
76
+ else
77
+ server_interaction { netuitived_server.exceptionEvent(hash, klass, tags) }
78
+ end
79
+ end
80
+ end
81
+
82
+ def flush_samples
83
+ NetuitiveRubyApi::ErrorLogger.guard('error during flush_samples') do
84
+ sample = data_cache.clear_sample_cache
85
+ num = sample[:samples].size + sample[:counter_samples].size + sample[:aggregate_metrics].size + sample[:aggregate_counter_metrics].size
86
+ NetuitiveRubyApi::NetuitiveLogger.log.info "sending #{num} samples" if num > 0
87
+ threads = []
88
+ threads << server_interaction do
89
+ NetuitiveRubyApi::NetuitiveLogger.log.debug "sending samples: #{sample[:samples]} "
90
+ netuitived_server.add_samples sample[:samples]
91
+ end unless sample[:samples].empty?
92
+ threads << server_interaction do
93
+ NetuitiveRubyApi::NetuitiveLogger.log.debug "sending counter_samples: #{sample[:counter_samples]} "
94
+ netuitived_server.add_counter_samples sample[:counter_samples]
95
+ end unless sample[:counter_samples].empty?
96
+ threads << server_interaction do
97
+ NetuitiveRubyApi::NetuitiveLogger.log.debug "sending aggregate_metrics: #{sample[:aggregate_metrics]} "
98
+ netuitived_server.add_aggregate_metrics sample[:aggregate_metrics]
99
+ end unless sample[:aggregate_metrics].empty?
100
+ threads << server_interaction do
101
+ NetuitiveRubyApi::NetuitiveLogger.log.debug "sending aggregate_counter_metrics: #{sample[:aggregate_counter_metrics]} "
102
+ netuitived_server.add_aggregate_counter_metrics sample[:aggregate_counter_metrics]
103
+ end unless sample[:aggregate_counter_metrics].empty?
104
+ threads
105
+ end
106
+ end
107
+
108
+ def flush_events
109
+ NetuitiveRubyApi::ErrorLogger.guard('error during flush_events') do
110
+ event_cache = data_cache.clear_event_cache
111
+ num = event_cache[:events].size + event_cache[:exception_events].size
112
+ NetuitiveRubyApi::NetuitiveLogger.log.info "sending #{num} events" if num > 0
113
+ threads = []
114
+ threads << server_interaction do
115
+ NetuitiveRubyApi::NetuitiveLogger.log.debug "sending events: #{event_cache[:events]} "
116
+ netuitived_server.add_events(event_cache[:events])
117
+ end unless event_cache[:events].empty?
118
+ threads << server_interaction do
119
+ NetuitiveRubyApi::NetuitiveLogger.log.debug "sending exception_events: #{event_cache[:exception_events]} "
120
+ netuitived_server.add_exception_events(event_cache[:exception_events])
121
+ end unless event_cache[:exception_events].empty?
122
+ threads
123
+ end
124
+ end
125
+
126
+ def sample_cache_addition
127
+ NetuitiveRubyAPI.check_restart
128
+ flush_samples if yield >= @sample_cache_size
129
+ end
130
+
131
+ def event_cache_addition
132
+ NetuitiveRubyAPI.check_restart
133
+ flush_events if yield >= @event_cache_size
134
+ end
135
+
136
+ def server_interaction
137
+ Thread.new do
138
+ NetuitiveRubyApi::ErrorLogger.guard('error during server interaction') { yield }
139
+ end
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,21 @@
1
+ # Important! ruby rescue logic is expensive.
2
+ # This class is *intended* to be used as a catch all, because we don't want any errors to not be logged
3
+ # or worse to bubble up to the host application.
4
+ # That *doesn't* mean we should be throwing exceptions rather than guarding against them
5
+ # From the benchmarks I've read it seems like rescues are free if no exception is thrown
6
+ module NetuitiveRubyApi
7
+ class ErrorLogger
8
+ class << self
9
+ def guard(message)
10
+ yield
11
+ rescue => e
12
+ NetuitiveRubyApi::NetuitiveLogger.log.error format_exception(e, message)
13
+ end
14
+
15
+ def format_exception(exception, *message)
16
+ message = '' unless defined? message || message.nil?
17
+ "#{message} \n\tException message: #{exception.message}\n\t Backtrace: #{exception.backtrace.join("\n\t")}"
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ module NetuitiveRubyApi
2
+ class EventSchedule
3
+ def self.start(interval)
4
+ @@thread = Thread.new do
5
+ loop do
6
+ sleep(interval)
7
+ Thread.new do
8
+ NetuitiveRubyApi::NetuitiveLogger.log.debug 'started event job'
9
+ NetuitiveRubyApi::ErrorLogger.guard('error during event job') do
10
+ NetuitiveRubyAPI.flush_events
11
+ end
12
+ NetuitiveRubyApi::NetuitiveLogger.log.debug 'finished event job'
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ def self.stop
19
+ @@thread.kill if defined? @@thread
20
+ end
21
+ end
22
+ end
@@ -14,7 +14,7 @@ module NetuitiveRubyApi
14
14
 
15
15
  class NetuitiveLogger
16
16
  class << self
17
- attr_reader :log
17
+ attr_accessor :log
18
18
  def setup
19
19
  file = NetuitiveRubyApi::ConfigManager.property('logLocation', 'NETUITIVE_RUBY_LOG_LOCATION', "#{File.expand_path('../../..', __FILE__)}/log/netuitive.log")
20
20
  age = NetuitiveRubyApi::ConfigManager.property('logAge', 'NETUITIVE_RUBY_LOG_AGE', 'daily')
@@ -0,0 +1,22 @@
1
+ module NetuitiveRubyApi
2
+ class SampleSchedule
3
+ def self.start(interval)
4
+ @@thread = Thread.new do
5
+ loop do
6
+ sleep(interval)
7
+ Thread.new do
8
+ NetuitiveRubyApi::NetuitiveLogger.log.debug 'started sample job'
9
+ NetuitiveRubyApi::ErrorLogger.guard('error during sample job') do
10
+ NetuitiveRubyAPI.flush_samples
11
+ end
12
+ NetuitiveRubyApi::NetuitiveLogger.log.debug 'finished sample job'
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ def self.stop
19
+ @@thread.kill if defined? @@thread
20
+ end
21
+ end
22
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netuitive_ruby_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,16 +9,37 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-10-17 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2016-10-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: netuitived
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.1.0
14
30
  description: Allows for easy submittion of metrics to Netuitive
15
31
  email: jking@netuitive.com
16
32
  executables: []
17
33
  extensions: []
18
34
  extra_rdoc_files: []
19
35
  files:
36
+ - lib/netuitive_ruby_api/sample_schedule.rb
20
37
  - lib/netuitive_ruby_api/netuitive_logger.rb
38
+ - lib/netuitive_ruby_api/data_manager.rb
39
+ - lib/netuitive_ruby_api/data_cache.rb
21
40
  - lib/netuitive_ruby_api/config_manager.rb
41
+ - lib/netuitive_ruby_api/event_schedule.rb
42
+ - lib/netuitive_ruby_api/error_logger.rb
22
43
  - lib/netuitive_ruby_api.rb
23
44
  - config/agent.yml
24
45
  - ./LICENSE