heroku_mongo_watcher 0.1.1.beta → 0.2.1.beta

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -34,6 +34,7 @@ The output looks like the following ...
34
34
  <tr><td>max</td><td>max request time</td></tr>
35
35
  <tr><td>r_err</td><td>number of router errors, i.e. timeouts</td></tr>
36
36
  <tr><td>w_err</td><td>number of web errros (see below)</td></tr>
37
+ <tr><td>%err</td><td>total errors divided by total requests</td></tr>
37
38
  <tr><td>wait</td><td>average router wait</td></tr>
38
39
  <tr><td>queue</td><td>average router queue</td></tr>
39
40
  <tr><td>slowest</td><td>path of the url that corresponds to the max request time</td></tr>
@@ -51,7 +52,7 @@ At least for me, one of the key features is aggregating signals from my web log
51
52
  and other errors). You can can configure the `error_messages` array in your .watcher file to define which String we
52
53
  should report on.
53
54
 
54
- In concert with that is the `display_errors` configuration. If set to true it will aggregate and display the errors
55
+ In concert with that is the `print_errors` configuration. If set to true it will aggregate and display the errors
55
56
  found (see output above), set to false it will just put the total in the summary row
56
57
 
57
58
 
@@ -66,3 +67,10 @@ found (see output above), set to false it will just put the total in the summary
66
67
  2. create a .watcher file (see the examples) in your user directory ~/.watcher
67
68
  3. then run `bundle exec watcher`
68
69
  4. Ctrl-C out to quit
70
+
71
+ ## Options
72
+
73
+ * `--print-errors` to print a summary of errors during each sample
74
+ * `--print-requests` to print a summary of requests during each sample
75
+
76
+ note: you can set these defaults in your .watcher file
data/example/.watcher CHANGED
@@ -26,4 +26,7 @@ heroku_appname: 'my-heroku-app-name'
26
26
  heroku_account: 'my-heroku-account'
27
27
 
28
28
  # If you want to display the list of errors in the logs
29
- display_errors: true
29
+ print_errors: true
30
+
31
+ # If you want to display the list of requests in the logs
32
+ print_requests: false
@@ -72,7 +72,8 @@ class HerokuMongoWatcher::CLI
72
72
 
73
73
  HerokuMongoWatcher::DataRow.print_header
74
74
 
75
- IO.popen("mongostat --rowcount 0 #{config[:interval]} --host #{config[:mongo_host]} --username #{config[:mongo_username]} --password #{config[:mongo_password]} --noheaders") do |f|
75
+ #IO.popen("mongostat --rowcount 0 #{config[:interval]} --host #{config[:mongo_host]} --username #{config[:mongo_username]} --password #{config[:mongo_password]} --noheaders") do |f|
76
+ IO.popen("mongostat --rowcount 0 10 --host #{config[:mongo_host]} --username #{config[:mongo_username]} --password #{config[:mongo_password]} --noheaders") do |f|
76
77
  while line = f.gets
77
78
  next unless line =~ /^/ && !(line =~ /^connected/)
78
79
  @mutex.synchronize do
@@ -163,7 +164,7 @@ class HerokuMongoWatcher::CLI
163
164
  "Faults: #{@last_row.faults}",
164
165
  "NetI/O: #{@last_row.net_in}/#{@last_row.net_out}",
165
166
  ]
166
- content = content + @last_row.error_content_for_email
167
+ content = content + @last_row.error_content_for_email + @last_row.request_content_for_email
167
168
 
168
169
  content = content.join("\r\n")
169
170
  Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
@@ -15,7 +15,8 @@ class HerokuMongoWatcher::Configuration
15
15
  mongo_password: '',
16
16
  heroku_appname: '',
17
17
  heroku_account: '',
18
- print_errors: true
18
+ print_errors: false,
19
+ print_requests: false
19
20
  }
20
21
 
21
22
  @@valid_config_keys = @@config.keys
@@ -25,7 +26,8 @@ class HerokuMongoWatcher::Configuration
25
26
  configure_with(f)
26
27
 
27
28
  opts = Trollop::options do
28
- opt :print_errors, "show aggregate error summaries", default: true
29
+ opt :print_errors, "show aggregate error summaries", default: false
30
+ opt :print_requests, "show aggregate requests summaries", default: false
29
31
  end
30
32
 
31
33
  @@config.merge!(opts)
@@ -5,7 +5,7 @@ class HerokuMongoWatcher::DataRow
5
5
  # Heroku Attributes
6
6
  @@attributes = [:total_requests, :total_service, :total_wait,
7
7
  :total_queue, :total_router_errors, :total_web_errors,
8
- :max_service, :slowest_request, :errors, :dynos]
8
+ :max_service, :slowest_request, :errors, :requests,:dynos]
9
9
 
10
10
  # Mongo Attributes
11
11
  @@attributes.concat [:inserts, :queries, :ops, :updates, :deletes,
@@ -17,6 +17,7 @@ class HerokuMongoWatcher::DataRow
17
17
  @@attributes.each { |attr| send "#{attr}=", 0 }
18
18
  self.slowest_request = nil
19
19
  self.errors = {}
20
+ self.requests = {}
20
21
  end
21
22
 
22
23
  def config
@@ -58,6 +59,8 @@ class HerokuMongoWatcher::DataRow
58
59
  status = items[8].split('=').last if items[8]
59
60
  bytes = items[9].split('=').last if items[9]
60
61
 
62
+ path = URI('http://' + url).path
63
+
61
64
  if is_number?(service) && is_number?(wait) && is_number?(queue)
62
65
  self.total_requests +=1
63
66
  self.total_service += Integer(service) if service
@@ -65,10 +68,17 @@ class HerokuMongoWatcher::DataRow
65
68
  self.total_queue += Integer(queue) if queue
66
69
  if Integer(service) > self.max_service
67
70
  self.max_service = Integer(service)
68
- self.slowest_request = URI('http://' + url).path
71
+ self.slowest_request = path
69
72
  end
70
73
  end
71
74
 
75
+ if self.requests.has_key? path
76
+ self.requests[path] = self.requests[path] + 1
77
+ else
78
+ self.requests[path] = 1
79
+ end
80
+
81
+
72
82
  end
73
83
  end
74
84
 
@@ -126,7 +136,8 @@ class HerokuMongoWatcher::DataRow
126
136
  end
127
137
 
128
138
  def print_row
129
- print_errors
139
+ print_hash(@errors) if config[:print_errors]
140
+ print_hash(@requests) if config[:print_requests]
130
141
 
131
142
  color_print @dynos, length: 4
132
143
  color_print @total_requests, warning: 30_000, critical: 50_000
@@ -150,10 +161,10 @@ class HerokuMongoWatcher::DataRow
150
161
  printf "\n"
151
162
  end
152
163
 
153
- def print_errors
154
- if config[:print_errors] && @errors && @errors.keys && @errors.keys.length > 0
155
- @errors.each do |error,count|
156
- puts "\t\t[#{count}] #{error}"
164
+ def print_hash(hash)
165
+ if hash && hash.keys && hash.keys.length > 0
166
+ hash.sort_by{|key,count| -count}.each do |row|
167
+ printf "\t%10s %s\n", "[#{row.last}]", row.first
157
168
  end
158
169
  end
159
170
  end
@@ -161,6 +172,7 @@ class HerokuMongoWatcher::DataRow
161
172
  def error_content_for_email
162
173
  content = []
163
174
  if @errors && @errors.keys && @errors.keys.length > 0
175
+ content << ""
164
176
  content << "Errors"
165
177
  @errors.each do |error,count|
166
178
  content << "\t\t[#{count}] #{error}"
@@ -169,6 +181,18 @@ class HerokuMongoWatcher::DataRow
169
181
  content
170
182
  end
171
183
 
184
+ def request_content_for_email
185
+ content = []
186
+ if @requests && @requests.keys && @requests.keys.length > 0
187
+ content << ""
188
+ content << "Requests"
189
+ @requests.sort_by{|req,count| -count}.each do |row|
190
+ content << "\t\t[#{row.last}] #{row.first}"
191
+ end
192
+ end
193
+ content
194
+ end
195
+
172
196
  private
173
197
 
174
198
  def is_number?(string)
@@ -183,9 +207,9 @@ class HerokuMongoWatcher::DataRow
183
207
 
184
208
  def color_print(field, options ={})
185
209
  options[:length] = 7 unless options[:length]
186
- print Term::ANSIColor.bold if options[:bold] == true
210
+ print Term::ANSIColor.bold if options[:bold]
187
211
  if options[:critical] && is_number?(field) && Float(field) > options[:critical]
188
- print "\a" #beep
212
+ beep
189
213
  print Term::ANSIColor.red
190
214
  print Term::ANSIColor.bold
191
215
  elsif options[:warning] && is_number?(field) && Float(field) > options[:warning]
@@ -200,5 +224,9 @@ class HerokuMongoWatcher::DataRow
200
224
  print Term::ANSIColor.clear
201
225
  end
202
226
 
227
+ def beep
228
+ print "\a"
229
+ end
230
+
203
231
 
204
232
  end
@@ -1,3 +1,3 @@
1
1
  module HerokuMongoWatcher
2
- VERSION = "0.1.1.beta"
2
+ VERSION = "0.2.1.beta"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heroku_mongo_watcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1.beta
4
+ version: 0.2.1.beta
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-23 00:00:00.000000000Z
12
+ date: 2012-07-24 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: term-ansicolor
16
- requirement: &2158231140 !ruby/object:Gem::Requirement
16
+ requirement: &2156725900 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2158231140
24
+ version_requirements: *2156725900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: tlsmail
27
- requirement: &2158230500 !ruby/object:Gem::Requirement
27
+ requirement: &2156724780 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2158230500
35
+ version_requirements: *2156724780
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: heroku
38
- requirement: &2158229820 !ruby/object:Gem::Requirement
38
+ requirement: &2156723920 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2158229820
46
+ version_requirements: *2156723920
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: trollop
49
- requirement: &2158229060 !ruby/object:Gem::Requirement
49
+ requirement: &2156722860 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *2158229060
57
+ version_requirements: *2156722860
58
58
  description: Also notifies you when certain thresholds are hit. I have found this
59
59
  much more accurate than New Relic
60
60
  email: