stackify-api-ruby 1.0.3 → 1.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 91576c0ba41af7311a30a4fad37f1d79d6094183
4
- data.tar.gz: cf5c824bb9ab986fcb497bc9ed1ed754a4f3093d
3
+ metadata.gz: df701108ebb0ac52a8a5195f2922474c492cea5d
4
+ data.tar.gz: 9e007bbdb78a24f3ec46a7271fa549b3d211b747
5
5
  SHA512:
6
- metadata.gz: 2b76008856dec9a3222956299826567e8c5f410c814034620bd4288f8e90104803b166163b83fd1aba30c7ba24596a558691b30017d5e61b16f6b320aa198038
7
- data.tar.gz: 4f5ec661d4004383633a6fe4807435cc447e697a81e54bc29603ac3566ba318effa84eb8a38e0b4db449675a945bbdb366dd28070bb0bf2e91be9f83371c1011
6
+ metadata.gz: 658c332b7564e08970931134aa26b971704acc9682609ef92a93c20d25e252ab5f60cbe775383cee144c8219d0b6b5e96cc4a67b57be1153250c8d5088bea271
7
+ data.tar.gz: 595d74f79383ad2aa17942f2a747d3d15e8f821d324abb0d021719f1114b3e910eb8321545e3b8d40064661f9d6990a2e5773598ac2c7c55022a4c3882140b60
data/README.md CHANGED
@@ -1,12 +1,20 @@
1
- # Stackify
1
+ # stackify-api-ruby
2
2
 
3
- Stackify Logs and Metrics API for Ruby
3
+ Stackify Logs and Metrics API for Ruby.
4
4
 
5
+ Errors and Logs Overview:
5
6
 
6
- Rails Installation
7
- ------------------
7
+ http://docs.stackify.com/m/7787/l/189767
8
8
 
9
- ### Rails 3.x/4.x
9
+ Sign Up for a Trial:
10
+
11
+ http://www.stackify.com/sign-up/
12
+
13
+ ## Installation and Configuration
14
+
15
+ Requirements: Ruby 1.9/2.0/2.1, Rails 3.x/4.x (optional)
16
+
17
+ ### Rails
10
18
 
11
19
  Add the stackify gem to your Gemfile. In Gemfile:
12
20
 
@@ -16,7 +24,7 @@ Run the bundle command to install it:
16
24
 
17
25
  $ bundle
18
26
 
19
- Or install it manually:
27
+ or install it manually:
20
28
 
21
29
  $ gem install stackify-api-ruby
22
30
 
@@ -26,15 +34,7 @@ After you install stackify-api-ruby you need to run the generator:
26
34
 
27
35
  The generator creates a file 'config/initializers/stackify.rb' configuring stackify-api-ruby with your API key. You can change default settings there.
28
36
 
29
- Usage: Logging
30
- ------------------
31
- ### Rails Environment
32
-
33
- stackify-api-ruby starts with start of Rails. Every error, which occurs within your application, will be caught and sent to Stackify automatically. The same situation with logs - you just use the Rails logger as usual:
34
-
35
- Rails.logger.info "Some log message"
36
-
37
- ### Other Environment
37
+ ### Non-Rails
38
38
 
39
39
  For using stackify-api-ruby gem within any Ruby application add to top of your main file:
40
40
 
@@ -46,40 +46,45 @@ After that you need to make base configuration:
46
46
  config.api_key = "your_api_key"
47
47
  config.env = :development
48
48
  config.app_name = "Your app name"
49
- config.app_location = "/somewhere/public"
50
49
  end
51
50
 
52
- "api_key" - it's you key for Stackify. "app-location" - it's location of your application for Nginx/Apache(for Nginx it's value of 'root', for Apache it's value of 'DocumentRoot' at config files).
51
+ ## Optional Configuration
53
52
 
54
53
  Gem has 3 modes of work - "both", "logging", "metrics". Mode "both" turns on both parts of gem - logging and metrics.
55
54
  If you need ONLY logging or metrics use "logging" or "metrics" mode accordingly.
56
55
 
57
56
  config.mode = :metrics
58
57
 
59
- You can set minimal level of logs, which should be caught by gem:
60
-
61
- config.log_level = :error
62
-
63
58
  If you want to use proxy for sending request, you can do it in such way:
64
59
 
65
60
  config.proxy = { uri: '127.0.0.1:8118', user: 'user_name', password: 'some_password' }
66
61
 
67
- For internal logging stackify-api-ruby uses such logger:
62
+ ## Log API Usage
68
63
 
69
- config.logger = Logger.new(File.join(Rails.root, "log", "stackify.log"))
64
+ ### Rails
65
+
66
+ stackify-api-ruby starts with start of Rails. Every error, which occurs within your application, will be caught and sent to Stackify automatically. The same situation with logs - you just use the Rails logger as usual:
67
+
68
+ Rails.logger.info "Some log message"
69
+
70
+ If you want to redefine <b>logger</b>, you should add
71
+
72
+ config.logger = ::Stackify::LoggerProxy.new(ActiveSupport::Logger.new(File.join(Rails.root, 'log', "#{Rails.env}.log")))
73
+
74
+ to your config/environments/%environment%. <b>Note:</b> in this case Stackify#config.log_level will affect entire system.
75
+
76
+ ### Non-Rails
70
77
 
71
78
  After logs configuring you should wrap up your logger:
72
79
 
73
80
  logger = Logger.new('mylog.log')
74
81
  logger = Stackify::LoggerProxy.new(logger)
75
82
 
76
-
77
83
  And last thing you need to do - call method "run":
78
84
 
79
85
  Stackify.run #remember that this call is running in the background of your main script
80
86
 
81
- Usage: Metrics
82
- ------------------
87
+ ## Metrics API Usage
83
88
 
84
89
  There are four different types of metrics:
85
90
 
@@ -99,6 +104,8 @@ There are four different types of metrics:
99
104
 
100
105
  t = Time.now
101
106
  Stackify::Metrics.time "MyCategory", "ElapsedTime", t
107
+ # or
108
+ Stackify::Metrics.time_duration "MyCategory", "ElapsedTime", 5.seconds
102
109
 
103
110
  - **Counter and Timer**: Composite of the Counter and Timer metrics for convenience
104
111
 
@@ -107,7 +114,7 @@ There are four different types of metrics:
107
114
 
108
115
  We can configure every metric with settings:
109
116
 
110
- settings = MetricSettings.new
117
+ settings = Stackify::Metrics::MetricSettings.new
111
118
  settings.autoreport_zero_if_nothing_reported = true
112
119
  # or
113
120
  settings.autoreport_last_value_if_nothing_reported = true
@@ -115,26 +122,27 @@ We can configure every metric with settings:
115
122
 
116
123
  Note, "autoreport_last_value_if_nothing_reported" property has influence only on "average" metric.
117
124
 
118
- Also there are two methods for getting last values of metrics:
119
-
120
- - get_latest - return last value of certain metric
125
+ ## Troubleshooting
121
126
 
122
- ``` Stackify::Metrics.get_latest "MyCategory", "MyCounter" ```
127
+ If there are problems, you can enable internal logging of the stackify-api-ruby project. Uncomment out the config.logger and config.logger.level lines in the 'config/initializers/stackify.rb' file:
123
128
 
124
- - get_latest_all_metrics - return all values of existed metrics
129
+ ```
130
+ config.logger = Logger.new(File.join(Rails.root, "log", "stackify.log"))
131
+ config.logger.level = Logger::DEBUG
132
+ ```
125
133
 
126
- ``` Stackify::Metrics.get_latest_all_metrics```
134
+ ## License
127
135
 
128
- ## Requirements
129
- Ruby: 1.9/2.0/2.1
136
+ Copyright 2015 Stackify, LLC.
130
137
 
131
- Rails: 3.x/4.x
138
+ Licensed under the Apache License, Version 2.0 (the "License");
139
+ you may not use this file except in compliance with the License.
140
+ You may obtain a copy of the License at
132
141
 
133
- Contributing
134
- ------------------
142
+ http://www.apache.org/licenses/LICENSE-2.0
135
143
 
136
- 1. Fork it ( https://github.com/[my-github-username]/stackify/fork )
137
- 2. Create your feature branch (`git checkout -b my-new-feature`)
138
- 3. Commit your changes (`git commit -am 'Add some feature'`)
139
- 4. Push to the branch (`git push origin my-new-feature`)
140
- 5. Create a new Pull Request
144
+ Unless required by applicable law or agreed to in writing, software
145
+ distributed under the License is distributed on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
147
+ See the License for the specific language governing permissions and
148
+ limitations under the License.
@@ -30,11 +30,11 @@ module Stackify::Authorizable
30
30
 
31
31
  def successfull_authorisation response
32
32
  Stackify::EnvDetails.instance.update_auth_info JSON.parse(response.body)
33
- Stackify.internal_log :info, 'Authorisation is finished successfully.'
33
+ Stackify.internal_log :info, 'Authorization is finished successfully.'
34
34
  end
35
35
 
36
36
  def unsuccessfull_authorisation response, caller
37
- Stackify.log_internal_error "Authorisation finally failed: #{response_string(response)}"
37
+ Stackify.log_internal_error "Authorization finally failed: #{response_string(response)}"
38
38
  Stackify.shutdown_all caller unless @@authorized
39
39
  end
40
40
 
@@ -22,7 +22,7 @@ module Stackify::Authorizable
22
22
  end
23
23
  }
24
24
  Stackify::ScheduleTask.new properties do
25
- Stackify.internal_log :debug, 'AthorizationClient: trying to athorize...'
25
+ Stackify.internal_log :debug, 'AthorizationClient: trying to authorize...'
26
26
  send_request BASE_URI, Stackify::EnvDetails.instance.auth_info.to_json
27
27
  end
28
28
  end
@@ -1,5 +1,9 @@
1
1
  module Stackify
2
-
2
+ class StringException < StandardError
3
+ def class
4
+ 'StringException'.freeze
5
+ end
6
+ end
3
7
  class StackifiedError < StandardError
4
8
 
5
9
  CONTEXT_PROPERTIES = { 'user' => 'current_user'}
@@ -5,11 +5,11 @@ module Stackify
5
5
  @@errors_governor = Stackify::ErrorsGovernor.new
6
6
  end
7
7
 
8
- def log level, msg
8
+ def log level, msg, call_trace
9
9
  Stackify::Utils.do_only_if_authorized_and_mode_is_on Stackify::MODES[:logging] do
10
10
  if acceptable? level, msg && Stackify.working?
11
11
  worker = Stackify::AddMsgWorker.new
12
- task = log_message_task level, msg
12
+ task = log_message_task level, msg, call_trace
13
13
  worker.async_perform ScheduleDelay.new, task
14
14
  end
15
15
  end
@@ -56,9 +56,22 @@ module Stackify
56
56
  Stackify.configuration.env.downcase.to_sym == Stackify::EnvDetails.instance.auth_info['ConfiguredEnvironmentName'].downcase.to_sym
57
57
  end
58
58
 
59
- def log_message_task level, msg
59
+ def log_message_task level, msg, call_trace
60
60
  Stackify::ScheduleTask.new ({limit: 1}) do
61
- Stackify.msgs_queue << Stackify::MsgObject.new(level, msg, caller[0]).to_h
61
+ if %w(error fatal).include?(level)
62
+ ex = if ruby_exception?(msg) && msg.class != Class
63
+ msg.set_backtrace(call_trace)
64
+ msg
65
+ else
66
+ e = StringException.new(msg)
67
+ e.set_backtrace(call_trace)
68
+ e
69
+ end
70
+ ex = StackifiedError.new(ex, binding())
71
+ Stackify.msgs_queue << Stackify::MsgObject.new(level, ex.message, caller[0], ex).to_h
72
+ else
73
+ Stackify.msgs_queue << Stackify::MsgObject.new(level, msg, caller[0]).to_h
74
+ end
62
75
  end
63
76
  end
64
77
 
@@ -67,6 +80,16 @@ module Stackify
67
80
  Stackify.msgs_queue << Stackify::MsgObject.new(level, ex.message, caller[0], ex).to_h
68
81
  end
69
82
  end
83
+
84
+ def ruby_exception? klass
85
+ klass = klass.class == Class ? klass : klass.class
86
+ klasses = [klass]
87
+ while klass != Object do
88
+ klasses << klass.superclass
89
+ klass = klass.superclass
90
+ end
91
+ klasses.include?(Exception)
92
+ end
70
93
  end
71
94
 
72
95
  end
@@ -4,12 +4,17 @@ module Stackify
4
4
  def initialize logger
5
5
  @logger = logger
6
6
  @logger.level = Logger.const_get(Stackify.configuration.log_level.to_s.upcase)
7
- %w( debug info warn error fatal unknown).each do |level|
7
+ %w(debug info warn error fatal unknown).each do |level|
8
+ stackify_logger = if level == 'debug'
9
+ -> (msg, caller) { Stackify.logger_client.log(level.downcase, msg, caller) unless msg.empty? }
10
+ else
11
+ -> (msg, caller) { Stackify.logger_client.log(level.downcase, msg, caller) }
12
+ end
8
13
  LoggerProxy.class_eval do
9
14
  define_method level.to_sym do |*args , &block|
10
- msg = message(args, block)
11
- Stackify.logger_client.log(level.downcase, msg)
12
- @logger.send(level.to_sym, args, &block)
15
+ msg = message(*args, &block)
16
+ stackify_logger.call(msg, caller)
17
+ @logger.send(level.to_sym, msg, &block)
13
18
  end
14
19
  end
15
20
  end
@@ -24,10 +29,12 @@ module Stackify
24
29
  private
25
30
 
26
31
  def message *args, &block
27
- if block
32
+ if block_given?
28
33
  block.call
29
34
  else
30
- args.flatten[0]
35
+ args = args.flatten.compact
36
+ args = (args.count == 1 ? args[0] : args)
37
+ args.is_a?(Proc) ? args.call : args
31
38
  end
32
39
  end
33
40
 
@@ -2,7 +2,7 @@ module Stackify::Metrics
2
2
  class MetricAggregate
3
3
 
4
4
  attr_accessor :name, :category, :value, :count, :occurred_utc,
5
- :monitor_id, :metric_type, :name_key
5
+ :monitor_id, :metric_type, :name_key, :sent, :is_increment
6
6
 
7
7
  def initialize metric
8
8
  @name = metric.name
@@ -12,6 +12,8 @@ module Stackify::Metrics
12
12
  @count = 0
13
13
  @occurred_utc = metric.get_rounded_time
14
14
  @name_key = metric.calc_name_key
15
+ @sent = false
16
+ @is_increment = metric.is_increment
15
17
  end
16
18
 
17
19
  def aggregate_key
@@ -38,7 +40,6 @@ module Stackify::Metrics
38
40
 
39
41
  def to_h
40
42
  {
41
- 'Count' => @count,
42
43
  'MetricType' => @metric_type,
43
44
  'MetricID' => @metric_id,
44
45
  'Name' => @name,
@@ -62,14 +62,19 @@ module Stackify
62
62
  Stackify::Metrics.metrics_client.queue_metric m
63
63
  end
64
64
 
65
- def time category, metric_name, start_time
65
+ def time category, metric_name, start_time, advanced_settings = nil
66
66
  time_taken = Time.now.utc - start_time.utc
67
- avarage_time category, metric_name, time_taken
67
+ avarage_time category, metric_name, time_taken, advanced_settings
68
68
  end
69
69
 
70
- def avarage_time category, metric_name, elapsed_time
70
+ def time_duration category, metric_name, duration_time, advanced_settings = nil
71
+ avarage_time category, metric_name, duration_time, advanced_settings
72
+ end
73
+
74
+ def avarage_time category, metric_name, elapsed_time, advanced_settings = nil
71
75
  m = Metric.new category, metric_name, Stackify::Metrics::METRIC_TYPES[:counter_time]
72
76
  m.value = elapsed_time.round #seconds
77
+ m.settings = advanced_settings
73
78
  Stackify::Metrics.metrics_client.queue_metric m
74
79
  end
75
80
 
@@ -60,82 +60,41 @@ module Stackify::Metrics
60
60
  #read everything up to the start of the current minute
61
61
  read_queued_metrics_batch current_time
62
62
  handle_zero_reports current_time
63
- get_for_recent = @aggregate_metrics.select do |_k, v|
64
- v.occurred_utc < current_time && v.occurred_utc > current_time - 5.minutes
65
- end
66
- set_latest_aggregates get_for_recent
67
- selected_aggr_metrics = @aggregate_metrics.select { |_key, aggr| aggr.occurred_utc < current_time }
63
+
64
+ selected_aggr_metrics = @aggregate_metrics.select { |_key, aggr| aggr.occurred_utc.to_i < current_time.to_i && !aggr.sent }
68
65
  first_50_metrics = Hash[selected_aggr_metrics.to_a.take 50]
69
66
  if first_50_metrics.length > 0
70
67
  #only getting metrics less than 10 minutes old to drop old data in case we get backed up
71
68
  #they are removed from the @aggregated_metrics in the upload function upon success
72
- all_success = upload_aggregates(first_50_metrics.select { |_key, aggr| aggr.occurred_utc > current_time - 10.minutes })
69
+ upload_aggregates(first_50_metrics.select { |_key, aggr| aggr.occurred_utc > current_time - 10.minutes })
73
70
  end
74
71
  @aggregate_metrics.delete_if { |_key, aggr| aggr.occurred_utc < purge_older_than }
75
72
  end
76
73
 
77
- def read_queued_metrics_batch chosen_time
78
- batches = {}
79
-
74
+ def read_queued_metrics_batch current_time
80
75
  while @metrics_queue.size > 0 do
76
+ break if Stackify::Utils.rounded_current_time.to_i != current_time.to_i
81
77
  metric = @metrics_queue.pop
82
78
  metric.calc_and_set_aggregate_key
83
- unless batches.has_key? metric.aggregate_key
84
- name_key = metric.calc_name_key
85
- if metric.is_increment && @last_aggregates.has_key?(name_key)
86
- #if wanting to do increments we need to grab the last value so we know what to increment
87
- metric.value = @last_aggregates[name_key].value
88
- end
89
- batches[metric.aggregate_key] = MetricAggregate.new metric
90
- #if it is nil don't do anything
91
- #we are doing it where the aggregates are created so we don't do it one very single metric,
92
- #just once per batch to optimize performance
93
-
94
- @metric_settings[name_key] = metric.settings if metric.settings != nil
79
+ metric_for_aggregation = MetricAggregate.new(metric)
80
+ name_key = metric.calc_name_key
81
+ if @last_aggregates.has_key?(name_key) &&
82
+ (metric.is_increment || @last_aggregates[name_key].occurred_utc.to_i == current_time.to_i)
83
+ metric_for_aggregation.value = @last_aggregates[name_key].value
84
+ metric_for_aggregation.count = @last_aggregates[name_key].count
95
85
  end
96
- batches[metric.aggregate_key].count += 1
97
- if metric.is_increment
98
- #add or subtract
99
- batches[metric.aggregate_key].value += metric.value
100
- elsif metric.metric_type == Stackify::Metrics::METRIC_TYPES[:metric_last]
101
- #should end up the last value
102
- batches[metric.aggregate_key].value = metric.value
103
- else
104
- batches[metric.aggregate_key].value += metric.value
105
- end
106
- #we don't need anything more this recent so bail
107
- break if metric.occurred > chosen_time
108
- end
109
- batches.each_pair do |_key, aggregated_metric|
110
- aggregate aggregated_metric
111
- end
112
- end
113
86
 
114
- def aggregate am
115
- agg_key = am.aggregate_key
116
- if @aggregate_metrics.has_key? agg_key
117
- agg = @aggregate_metrics[agg_key]
118
- else
119
- if @aggregate_metrics.length > 1000
120
- str = 'No longer aggregating new metrics because more than 1000 are queued'
121
- Stackify.internal_log :warn, str
122
- return
123
- end
124
- Stackify.internal_log :debug, 'Creating aggregate for ' + agg_key
125
- @aggregate_metrics[agg_key] = am
126
- agg = Stackify::Metrics::Metric.new am.category, am.name, am.metric_type
127
- agg = MetricAggregate.new agg
128
- agg.occurred_utc = am.occurred_utc
129
- end
87
+ @metric_settings[name_key] = metric.settings if metric.settings != nil
130
88
 
131
- if am.metric_type == Stackify::Metrics::METRIC_TYPES[:metric_last]
132
- agg.count = 1
133
- agg.value = am.value
134
- else
135
- agg.count += am.count
136
- agg.value += am.value
89
+ if metric.metric_type == Stackify::Metrics::METRIC_TYPES[:metric_last] && !metric.is_increment
90
+ metric_for_aggregation.value = metric.value
91
+ metric_for_aggregation.count = 1
92
+ else
93
+ metric_for_aggregation.value += metric.value
94
+ metric_for_aggregation.count += 1
95
+ end
96
+ @last_aggregates[name_key] = @aggregate_metrics[metric.aggregate_key] = metric_for_aggregation
137
97
  end
138
- @aggregate_metrics[agg_key]= agg
139
98
  end
140
99
 
141
100
  def submit_metrics_task
@@ -152,20 +111,22 @@ module Stackify::Metrics
152
111
  @metric_settings.delete[aggregate.name_key]
153
112
  next
154
113
  end
155
- #agg = MetricAggregate.new aggregate.category, aggregate.name, aggregate.metric_type
156
- agg = aggregate
114
+ agg = aggregate.clone
157
115
  agg.occurred_utc = current_time
158
- case aggregate.metric_type
159
- when Stackify::Metrics::METRIC_TYPES[:metric_last]
160
- setting.autoreport_last_value_if_nothing_reported = false #do not allow this
161
- when Stackify::Metrics::METRIC_TYPES[:counter]
162
- setting.autoreport_last_value_if_nothing_reported = false #do not allow this
116
+
117
+ disabled_autoreport_last = [
118
+ Stackify::Metrics::METRIC_TYPES[:counter],
119
+ Stackify::Metrics::METRIC_TYPES[:timer]
120
+ ]
121
+ if disabled_autoreport_last.include? aggregate.metric_type
122
+ settings.autoreport_last_value_if_nothing_reported = false #do not allow this
163
123
  end
124
+
164
125
  if settings.autoreport_zero_if_nothing_reported
165
- agg.count = 1
126
+ agg.count = 0
166
127
  agg.value = 0
167
128
  elsif settings.autoreport_last_value_if_nothing_reported
168
- agg.count = aggregate.value.to_i
129
+ agg.count = aggregate.count.to_i
169
130
  agg.value = aggregate.value
170
131
  else
171
132
  next
@@ -173,7 +134,8 @@ module Stackify::Metrics
173
134
  agg_key = agg.aggregate_key
174
135
  unless @aggregate_metrics.has_key? agg_key
175
136
  agg.name_key = aggregate.name_key
176
- Stackify.internal_log :debug, 'Creating 0 default value for ' + agg_key
137
+ agg.sent = false
138
+ Stackify.internal_log :debug, 'Creating default value for ' + agg_key
177
139
  @aggregate_metrics[agg_key] = agg
178
140
  end
179
141
  end
@@ -192,18 +154,13 @@ module Stackify::Metrics
192
154
  end
193
155
 
194
156
  def upload_aggregates aggr_metrics
195
- s = ''
196
- aggr_metrics.each_pair do |_k, m|
197
- s = s + m.inspect.to_s + "\n --------------------------- \n"
198
- end
199
- Stackify.internal_log :debug, "Uploading Aggregate Metrics at #{ Time.now }: \n" + s
200
157
  all_success = true
201
158
  aggr_metrics.each_pair do |_key, metric|
202
159
  if @monitor_ids.has_key? metric.name_key
203
160
  mon_info = @monitor_ids[metric.name_key]
204
161
  else
205
162
  req = @metrics_sender.monitor_info metric
206
- if req.try(:code) == '200'
163
+ if req.try(:status) == 200
207
164
  mon_info = JSON.parse req.body
208
165
  if !mon_info.nil? && !mon_info['MonitorID'].nil? && mon_info['MonitorID'] > 0
209
166
  @monitor_ids[metric.name_key] = mon_info
@@ -225,13 +182,12 @@ module Stackify::Metrics
225
182
  else
226
183
  metric.monitor_id = mon_info['MonitorID']
227
184
  end
228
-
229
- #get identified once
230
- aggr_metrics_for_upload = aggr_metrics.select { |_key, aggr_metric| !aggr_metric.monitor_id.nil? }
231
- response = @metrics_sender.upload_metrics aggr_metrics_for_upload
232
- Stackify.internal_log :info, 'Metrics are uploaded successfully' if response.try(:code) == '200'
233
- all_success
234
185
  end
186
+
187
+ #get identified once
188
+ aggr_metrics_for_upload = aggr_metrics.select { |_key, aggr_metric| !aggr_metric.monitor_id.nil? }
189
+ @metrics_sender.upload_metrics aggr_metrics_for_upload
190
+ all_success
235
191
  end
236
192
  end
237
193
  end
@@ -7,22 +7,27 @@ module Stackify::Metrics
7
7
  if Stackify.authorized?
8
8
  send_request GET_METRIC_INFO_URI, GetMetricRequest.new(aggr_metric).to_h.to_json
9
9
  else
10
- Stackify.log_internal_error "Getting of monitor_info is failed because of authorisation failure"
10
+ Stackify.log_internal_error "Getting of monitor_info is failed because of authorization failure"
11
11
  end
12
12
  end
13
13
 
14
14
  def upload_metrics aggr_metrics
15
15
  return true if aggr_metrics.nil? || aggr_metrics.length == 0
16
+ current_time = Stackify::Utils.rounded_current_time
16
17
  if Stackify.authorized?
17
18
  records = []
18
19
  aggr_metrics.each_pair do |_key, metric|
20
+ next if metric.sent || metric.occurred_utc.to_i >= current_time.to_i
19
21
  records << Stackify::Metrics::MetricForSubmit.new(metric).to_h
20
- prms = [metric.category, metric.name, metric.count, metric.value, metric.monitor_id ]
21
- Stackify.internal_log :debug, 'Uploading metric: %s: %s count %s, value %s, ID %s' % prms
22
+ metric.sent = true
23
+ end
24
+ if records.any?
25
+ Stackify.internal_log :debug, "Uploading Aggregate Metrics at #{ Time.now }: \n" + JSON.pretty_generate(records)
26
+ response = send_request SUBMIT_METRIS_URI, records.to_json
27
+ Stackify.internal_log :info, 'Metrics are uploaded successfully' if response.try(:status) == 200
22
28
  end
23
- send_request SUBMIT_METRIS_URI, records.to_json
24
29
  else
25
- Stackify.log_internal_error "Uploading of metrics is failed because of authorisation failure"
30
+ Stackify.log_internal_error "Uploading of metrics is failed because of authorization failure"
26
31
  end
27
32
  end
28
33
  end
@@ -17,11 +17,8 @@ module Stackify
17
17
  @send_interval = 60
18
18
  @log_level = :info
19
19
  @mode = MODES[:both]
20
- @logger = if defined? Rails
21
- Logger.new(File.join(Rails.root, 'log', 'stackify.log'))
22
- else
23
- Logger.new('stackify.log')
24
- end
20
+ @logger = Logger.new(STDOUT)
21
+ @logger.level = Logger::UNKNOWN
25
22
  end
26
23
 
27
24
  def is_valid?
@@ -10,7 +10,7 @@ module Stackify
10
10
  'data' => nil,
11
11
  'Ex' => @ex.try(:to_h),
12
12
  'Level' => @level.to_s.upcase!,
13
- 'Tags' => %w(ruby rails),
13
+ #'Tags' => %w(ruby rails),
14
14
  'EpochMs' => Time.now.to_f * 1000,
15
15
  'Th' => Thread.current.object_id.to_s,
16
16
  'TransID' => Stackify::EnvDetails.instance.request_details.try{ |d| d['uuid'] },
@@ -1,3 +1,3 @@
1
1
  module Stackify
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.4'
3
3
  end
@@ -27,6 +27,7 @@ module Stackify
27
27
  autoload :LogsSender, 'stackify/logs_sender'
28
28
  autoload :LoggerProxy, 'stackify/logger_proxy'
29
29
  autoload :StackifiedError, 'stackify/error'
30
+ autoload :StringException, 'stackify/error'
30
31
  autoload :ErrorsGovernor, 'stackify/errors_governor'
31
32
  autoload :Metrics, 'stackify/metrics/metrics'
32
33
 
@@ -5,7 +5,7 @@ require 'stackify/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'stackify-api-ruby'
8
- spec.version = '1.0.3'
8
+ spec.version = Stackify::VERSION
9
9
  spec.authors = ['Stackify']
10
10
  spec.email = ['support@stackify.com']
11
11
  spec.summary = 'Stackify API for Ruby'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stackify-api-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stackify
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-10 00:00:00.000000000 Z
11
+ date: 2015-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler