Class: HerokuMongoWatcher::DataRow
- Inherits:
-
Object
- Object
- HerokuMongoWatcher::DataRow
- Defined in:
- lib/heroku_mongo_watcher/data_row.rb
Constant Summary collapse
- @@attributes =
Heroku Attributes
[:total_requests, :total_service, :total_wait, :total_queue, :total_router_errors, :total_web_errors, :max_service, :slowest_request, :errors, :requests,:dynos]
Class Method Summary collapse
Instance Method Summary collapse
- #add_error(error_line) ⇒ Object
- #average_queue ⇒ Object
- #average_response_time ⇒ Object
- #average_wait ⇒ Object
- #config ⇒ Object
- #error_content_for_email ⇒ Object
- #error_rate ⇒ Object
-
#initialize ⇒ DataRow
constructor
A new instance of DataRow.
- #lock_request_ratio ⇒ Object
- #print_row ⇒ Object
- #process_heroku_router_line(line) ⇒ Object
- #process_heroku_web_line(line) ⇒ Object
- #process_mongo_line(line) ⇒ Object
- #request_content_for_email ⇒ Object
Constructor Details
#initialize ⇒ DataRow
Returns a new instance of DataRow.
17 18 19 20 21 22 |
# File 'lib/heroku_mongo_watcher/data_row.rb', line 17 def initialize @@attributes.each { |attr| send "#{attr}=", 0 } self.slowest_request = nil self.errors = {} self.requests = {} end |
Class Method Details
.print_header ⇒ Object
48 49 50 51 52 |
# File 'lib/heroku_mongo_watcher/data_row.rb', line 48 def self.print_header puts puts "|<---- heroku stats ------------------------------------------------------------------->|<----mongo stats ------------------------------------------------>|" puts "| dyno reqs art max r_err w_err %err wait queue slowest |insrt query updt flt lck lck:mrq qr|qw netI/O time |" end |
Instance Method Details
#add_error(error_line) ⇒ Object
141 142 143 144 145 146 147 |
# File 'lib/heroku_mongo_watcher/data_row.rb', line 141 def add_error(error_line) if self.errors.has_key? error_line self.errors[error_line] = self.errors[error_line] + 1 else self.errors[error_line] = 1 end end |
#average_queue ⇒ Object
36 37 38 |
# File 'lib/heroku_mongo_watcher/data_row.rb', line 36 def average_queue total_requests > 0 ? total_queue / total_requests : 'N/A' end |
#average_response_time ⇒ Object
28 29 30 |
# File 'lib/heroku_mongo_watcher/data_row.rb', line 28 def average_response_time total_requests > 0 ? total_service / total_requests : 'N/A' end |
#average_wait ⇒ Object
32 33 34 |
# File 'lib/heroku_mongo_watcher/data_row.rb', line 32 def average_wait total_requests > 0 ? total_wait / total_requests : 'N/A' end |
#config ⇒ Object
24 25 26 |
# File 'lib/heroku_mongo_watcher/data_row.rb', line 24 def config HerokuMongoWatcher::Configuration.instance.config end |
#error_content_for_email ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/heroku_mongo_watcher/data_row.rb', line 54 def error_content_for_email content = [] if @errors && @errors.keys && @errors.keys.length > 0 content << "" content << "Errors" @errors.each do |error,count| content << "\t\t[#{count}] #{error}" end end content end |
#error_rate ⇒ Object
40 41 42 |
# File 'lib/heroku_mongo_watcher/data_row.rb', line 40 def error_rate total_requests > 0 ? ((((total_web_errors + total_router_errors)*(1.0)) / total_requests)* 100).round(2) : 'N/A' end |
#lock_request_ratio ⇒ Object
44 45 46 |
# File 'lib/heroku_mongo_watcher/data_row.rb', line 44 def lock_request_ratio total_requests > 0 ? ((((Float(locked) * 1.0)/ total_requests)) * 1_000).round(2) : 'N/A' end |
#print_row ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/heroku_mongo_watcher/data_row.rb', line 176 def print_row print_hash(@errors) if config[:print_errors] print_hash(@requests) if config[:print_requests] color_print @dynos, length: 4 color_print @total_requests, warning: 30_000, critical: 50_000 color_print average_response_time, warning: 500, critical: 1000, bold: true color_print @max_service, warning: 20_000 color_print @total_router_errors, warning: 1 color_print @total_web_errors, warning: 1 color_print error_rate, warning: 1, critical: 3, percent: true color_print @total_wait #, warning: 10, critical: 100 color_print @total_queue #, warning: 10, critical: 100 color_print @slowest_request, length: 28, slice: 25 print '|' color_print @inserts, length: 5 color_print @queries, length: 6 color_print @updates, length: 5 color_print @faults, length: 5 color_print @locked, bold: true, warning: 40, critical: 70, length: 6, percent: true color_print lock_request_ratio color_print @qrw color_print "#{@net_in}/#{@net_out}", length: 10 color_print @mongo_time, length: 13 printf "\n" end |
#process_heroku_router_line(line) ⇒ Object
78 79 80 81 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 115 116 117 118 119 120 121 122 123 |
# File 'lib/heroku_mongo_watcher/data_row.rb', line 78 def process_heroku_router_line(line) items = line.split self.total_requests +=1 if line =~ /Error/ # Note: The lion share of these are timeouts #Full list here: https://devcenter.heroku.com/articles/error-codes self.total_router_errors += 1 time = items[0] process = items[1] clean_line = line.sub(time, '').sub(process, '').strip add_error(clean_line) else time = items[0] process = items[1] http_type = items[2] url = items[3] dyno = items[4].split('=').last if items[4] queue = items[5].split('=').last.sub('ms', '') if items[5] wait = items[6].split('=').last.sub('ms', '') if items[6] service = items[7].split('=').last.sub('ms', '') if items[7] status = items[8].split('=').last if items[8] bytes = items[9].split('=').last if items[9] path = extract_path(url) if is_number?(service) && is_number?(wait) && is_number?(queue) self.total_service += Integer(service) if service self.total_wait += Integer(wait) if wait self.total_queue += Integer(queue) if queue if Integer(service) > self.max_service self.max_service = Integer(service) self.slowest_request = path end end if self.requests.has_key? path self.requests[path] = self.requests[path] + 1 else self.requests[path] = 1 end end end |
#process_heroku_web_line(line) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/heroku_mongo_watcher/data_row.rb', line 125 def process_heroku_web_line(line) # Only care about errors = config[:error_messages] if .any? { |mes| line.include? mes } items = line.split time = items[0] process = items[1] clean_line = line.sub(time, '').sub(process, '').strip self.total_web_errors += 1 add_error(clean_line) end end |
#process_mongo_line(line) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/heroku_mongo_watcher/data_row.rb', line 149 def process_mongo_line(line) items = line.split @inserts = items[0] @queries = items[1] @updates = items[2] delete = items[3] getmore = items[4] command = items[5] flushes = items[6] mapped = items[7] vsize = items[8] res = items[9] @faults = items[10] @locked = items[11] idx_miss = items[12] @qrw = items[13] arw = items[14] @net_in = items[15] @net_out = items[16] conn = items[17] set = items[18] repl = items[19] @mongo_time = items[20] end |
#request_content_for_email ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/heroku_mongo_watcher/data_row.rb', line 66 def request_content_for_email content = [] if @requests && @requests.keys && @requests.keys.length > 0 content << "" content << "Requests" @requests.sort_by{|req,count| -count}.first(10).each do |row| content << "\t\t[#{row.last}] #{row.first}" end end content end |