rearview 1.0.3.rc.3-jruby → 1.0.3.rc.4-jruby

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8d18574480d2cb164b05a399d03d8471f0a2eb86
4
- data.tar.gz: 536a96e7c77dbdd0249713fa36fcd2e5b1a54cf1
3
+ metadata.gz: 1801238546921f09bd33e3a81516867ff5a4d73e
4
+ data.tar.gz: a64de87d9f977c2fdc88d0e95450c630ca82dadf
5
5
  SHA512:
6
- metadata.gz: e7894d65ca93d5e9ffd6b9a82e325b21a267806bc7a83ade90883063c8150a8a450a5bfe5f04629d0fd0652a4e1eca58e04bf58fcbc2bc09f2f576e87b826916
7
- data.tar.gz: eec2f7f6dbb2f9a290534408c6cc8faa5d3e2281934f7f87f466f97acc54b3a133ede123a17b6ec22dc387e44727d3ed5fd178728f8356aca291b378c1bd1de6
6
+ metadata.gz: 2a5aa2242148ddf22b6a5bd39b6c65f6e42acd9735d1acdf677ec91d7a227040dd10e246814ec4ce438b54d3c2e64fa22edfc3d2c4e164eb33343f52d7883299
7
+ data.tar.gz: 7e197973fdfa99f1cbf6fc511564d44af39950c10b2b93ea45d0f2a370fdc5fbe25f1677b8dc1178000db8c4f5d8cdbd44906cb1b75f1f47522b4a508b7d26d2
@@ -139,7 +139,6 @@ module Rearview
139
139
  end
140
140
 
141
141
  def create_associated_event(transition)
142
- logger.debug "#{self}#create_associated_event for transition #{transition.inspect}"
143
142
  report_transition(transition)
144
143
  job_error_attrs = {}
145
144
  job_error_attrs.merge!(event_data[:job_error]) if event_data.try(:[],:job_error)
@@ -148,7 +147,6 @@ module Rearview
148
147
  end
149
148
 
150
149
  def update_associated_event(transition)
151
- logger.debug "#{self}#update_associated_event for transition #{transition.inspect}"
152
150
  report_transition(transition)
153
151
  job_error = Rearview::JobError.latest_entry(self)
154
152
  if job_error.present?
@@ -101,14 +101,12 @@ module Rearview
101
101
  end
102
102
 
103
103
  def create_alert(transition)
104
- logger.debug "#{self}#create_alert for transition #{transition.inspect}"
105
104
  Rearview::AlertsHandler.new(self.job,event_data[:monitor_results]).run
106
105
  self.last_alerted_at = Time.now.utc
107
106
  save!
108
107
  end
109
108
 
110
109
  def update_alert(transition)
111
- logger.debug "#{self}#update_alert for transition #{transition.inspect}"
112
110
  if !self.last_alerted_at || Time.now.utc >= self.last_alerted_at.utc + self.job.error_timeout.minutes
113
111
  Rearview::AlertsHandler.new(self.job,event_data[:monitor_results]).run
114
112
  self.last_alerted_at = Time.now.utc
@@ -24,11 +24,6 @@ module Rearview
24
24
  logger.error "#{self} failed: #{$!}\n#{$@.join("\n")}"
25
25
  self
26
26
  end
27
-
28
- def to_s
29
- "#{super.to_s} [jobId:#{@job.id} threadId:#{java.lang.Thread.currentThread.getId} threadName:#{java.lang.Thread.currentThread.getName}]"
30
- end
31
-
32
27
  end
33
28
  end
34
29
 
@@ -0,0 +1,40 @@
1
+ # copied from logger.rb
2
+ module Rearview
3
+ class LogFormatter
4
+ Format = "%s, [%s#%d/%s] %5s -- %s: %s\n"
5
+
6
+ attr_accessor :datetime_format
7
+
8
+ def initialize
9
+ @datetime_format = nil
10
+ end
11
+
12
+ def call(severity, time, progname, msg)
13
+ thread_name = java.lang.Thread.currentThread.getName
14
+ default_name = ( progname.present? ? progname : "Rearview" )
15
+ Format % [severity[0..0],format_datetime(time),$$,thread_name,severity,default_name,msg2str(msg)]
16
+ end
17
+
18
+ private
19
+
20
+ def format_datetime(time)
21
+ if @datetime_format.nil?
22
+ time.strftime("%Y-%m-%dT%H:%M:%S.") << "%06d " % time.usec
23
+ else
24
+ time.strftime(@datetime_format)
25
+ end
26
+ end
27
+
28
+ def msg2str(msg)
29
+ case msg
30
+ when ::String
31
+ msg
32
+ when ::Exception
33
+ "#{ msg.message } (#{ msg.class })\n" <<
34
+ (msg.backtrace || []).join("\n")
35
+ else
36
+ msg.inspect
37
+ end
38
+ end
39
+ end
40
+ end
@@ -268,10 +268,6 @@ module Rearview
268
268
  [from,to]
269
269
  end
270
270
 
271
- def to_s
272
- "#{super.to_s} [threadId:#{java.lang.Thread.currentThread.getId} threadName:#{java.lang.Thread.currentThread.getName}]"
273
- end
274
-
275
271
  end
276
272
  end
277
273
  end
@@ -46,9 +46,6 @@ module Rearview
46
46
  def self.task_sym(job)
47
47
  "job_#{job.id}".to_sym
48
48
  end
49
- def to_s
50
- "#{super.to_s} [threadId:#{java.lang.Thread.currentThread.getId} threadName:#{java.lang.Thread.currentThread.getName}]"
51
- end
52
49
  end
53
50
  end
54
51
 
@@ -4,16 +4,16 @@ module Rearview
4
4
  class MonitorTask
5
5
  class MonitorTaskError < StandardError; end;
6
6
  include Celluloid
7
- include Celluloid::Logger
7
+ include Rearview::Logger
8
8
  attr_reader :job,:timer,:initial_delay
9
9
  def initialize(job,initial_delay=0,start=true)
10
- debug "#{self} intialize initial_delay:#{initial_delay} start:#{start}"
10
+ logger.debug "#{self} intialize initial_delay:#{initial_delay} start:#{start}"
11
11
  @job = job
12
12
  @initial_delay = initial_delay
13
13
  schedule if start
14
14
  end
15
15
  def schedule
16
- debug "#{self} schedule"
16
+ logger.debug "#{self} schedule"
17
17
  if ActiveRecord::Base.connection_pool.active_connection?
18
18
  ActiveRecord::Base.connection_pool.release_connection
19
19
  end
@@ -22,11 +22,11 @@ module Rearview
22
22
  @timer.cancel
23
23
  end
24
24
  delay = @job.delay + @initial_delay
25
- debug "#{self} next run in #{delay}s"
25
+ logger.debug "#{self} next run in #{delay}s"
26
26
  @timer = after(delay) { self.run }
27
27
  end
28
28
  def run
29
- debug "#{self} run"
29
+ logger.debug "#{self} run"
30
30
  @initial_delay = 0
31
31
  result = Rearview::MonitorRunner.run(@job.metrics, @job.monitor_expr, @job.minutes)
32
32
  ActiveRecord::Base.connection_pool.with_connection do
@@ -34,7 +34,7 @@ module Rearview
34
34
  Rearview::ResultsHandler.new(@job,result).run
35
35
  end
36
36
  rescue
37
- error "#{self} run failed: #{$!}\n#{$@.join("\n")}"
37
+ logger.error "#{self} run failed: #{$!}\n#{$@.join("\n")}"
38
38
  ActiveRecord::Base.connection_pool.with_connection do
39
39
  @job.last_run = Time.now.utc
40
40
  @job.error!
@@ -42,9 +42,6 @@ module Rearview
42
42
  ensure
43
43
  schedule
44
44
  end
45
- def to_s
46
- "#{super.to_s} [jobId:#{self.job.try(:id)||'nil'} threadId:#{java.lang.Thread.currentThread.getId} threadName:#{java.lang.Thread.currentThread.getName}]"
47
- end
48
45
  end
49
46
  end
50
47
 
@@ -32,7 +32,4 @@ module Rearview
32
32
  self
33
33
  end
34
34
  end
35
- def to_s
36
- "#{super.to_s} [jobId:#{@job.id} threadId:#{java.lang.Thread.currentThread.getId} threadName:#{java.lang.Thread.currentThread.getName}]"
37
- end
38
35
  end
@@ -4,7 +4,7 @@ module Rearview
4
4
  class StatsTask
5
5
  class StatsTaskError < StandardError; end;
6
6
  include Celluloid
7
- include Celluloid::Logger
7
+ include Rearview::Logger
8
8
  attr_reader :delay, :statsd
9
9
  def initialize(delay=120,start=true)
10
10
  @delay = delay
@@ -20,12 +20,12 @@ module Rearview
20
20
  end
21
21
 
22
22
  def schedule
23
- debug "#{self} schedule"
23
+ logger.debug "#{self} schedule"
24
24
  @timer = after(@delay) { self.run }
25
25
  end
26
26
 
27
27
  def run
28
- debug "#{self} run"
28
+ logger.debug "#{self} run"
29
29
  vm = Rearview::Vm.new
30
30
  @statsd.batch do |batch|
31
31
  batch.gauge('vm.total_memory',vm.total_memory.bytes_to_kilobytes)
@@ -42,7 +42,7 @@ module Rearview
42
42
  batch.gauge('monitor.total',( Rearview.config.monitor_enabled? ? Rearview.monitor_service.jobs.keys.count : 0 ))
43
43
  end
44
44
  rescue
45
- error "#{self} run failed: #{$!}\n#{$@.join("\n")}"
45
+ logger.error "#{self} run failed: #{$!}\n#{$@.join("\n")}"
46
46
  ensure
47
47
  schedule
48
48
  end
@@ -1,3 +1,3 @@
1
1
  module Rearview
2
- VERSION = "1.0.3.rc.3"
2
+ VERSION = "1.0.3.rc.4"
3
3
  end
data/lib/rearview.rb CHANGED
@@ -1,9 +1,10 @@
1
- require "rearview/engine"
2
- require "rearview/concerns"
3
- require "rearview/ext/state_machine"
4
- require "rearview/ext/numeric"
5
- require "rearview/constants_module_maker"
1
+ require 'rearview/engine'
2
+ require 'rearview/concerns'
3
+ require 'rearview/ext/state_machine'
4
+ require 'rearview/ext/numeric'
5
+ require 'rearview/constants_module_maker'
6
6
  require 'rearview/logger'
7
+ require 'rearview/log_formatter'
7
8
  require 'rearview/cron_helper'
8
9
  require 'rearview/graphite_parser'
9
10
  require 'rearview/results_handler'
@@ -52,29 +53,27 @@ module Rearview
52
53
  end
53
54
 
54
55
  def boot!
55
- @logger = config.logger if(config.logger.present?)
56
- logger.info "[#{self}] booting..."
57
- logger.info "[#{self}] using configuration: \n#{config.dump}"
56
+ Celluloid.logger = @logger = config.logger if(config.logger.present?)
57
+ logger.info "booting..."
58
+ logger.info "using configuration: \n#{config.dump}"
58
59
  if config.verify?
59
60
  unless config.valid?
60
- logger.warn "[#{self}] configuration check FAILED: \n#{config.errors.full_messages.join("\n")}"
61
+ logger.warn "configuration check FAILED: \n#{config.errors.full_messages.join("\n")}"
61
62
  end
62
63
  end
63
- Celluloid.logger = @logger
64
64
  jobs = ( config.preload_jobs? ? Job.schedulable : [] )
65
- logger.info "[#{self}] starting up monitor service for (#{jobs.count}) job(s)"
65
+ logger.info "starting up monitor service for (#{jobs.count}) job(s)"
66
66
  @monitor_service = Rearview::MonitorService.new(jobs)
67
67
  if config.monitor_enabled?
68
68
  @monitor_service.startup
69
69
  else
70
- logger.warn "[#{self}] monitor disabled"
70
+ logger.warn "monitor disabled!"
71
71
  end
72
72
  if config.stats_enabled?
73
- logger.info "[#{self}] starting up stats service"
73
+ logger.info "starting up stats service"
74
74
  @stats_service = Rearview::StatsService.supervise
75
75
  @stats_service.actors.first.startup
76
76
  end
77
-
78
77
  @alert_clients = Rearview::Alerts.registry.values
79
78
  @booted = true
80
79
  end
@@ -311,3 +311,21 @@
311
311
   (12.0ms) CREATE UNIQUE INDEX `unique_schema_migrations` ON `schema_migrations` (`version`)
312
312
   (1.0ms) SELECT version FROM `schema_migrations`
313
313
   (4.0ms) INSERT INTO `schema_migrations` (version) VALUES ('20131106162900')
314
+  (20.0ms) DROP DATABASE IF EXISTS `rearview_ruby_test`
315
+  (2.0ms) CREATE DATABASE `rearview_ruby_test` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`
316
+  (39.0ms) CREATE TABLE `applications` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `user_id` int(11), `name` varchar(255) NOT NULL, `created_at` datetime, `updated_at` datetime, `deleted_at` datetime, `ancestry` varchar(255), `description` varchar(255)) ENGINE=InnoDB DEFAULT CHARSET=utf8
317
+  (11.0ms) CREATE INDEX `index_applications_on_ancestry` ON `applications` (`ancestry`)
318
+  (9.0ms) CREATE INDEX `user_id` ON `applications` (`user_id`)
319
+  (8.0ms) CREATE TABLE `job_data` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `job_id` int(11) DEFAULT 0 NOT NULL, `created_at` datetime, `updated_at` datetime, `data` longtext NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8
320
+  (7.0ms) CREATE TABLE `job_errors` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `job_id` int(11), `created_at` datetime, `message` longtext, `status` varchar(255), `last_alerted_at` datetime, `updated_at` datetime) ENGINE=InnoDB DEFAULT CHARSET=utf8
321
+  (9.0ms) CREATE INDEX `job_id` ON `job_errors` (`job_id`)
322
+  (16.0ms) CREATE TABLE `jobs` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `created_at` datetime, `updated_at` datetime, `name` varchar(255) NOT NULL, `active` tinyint(1) DEFAULT 1 NOT NULL, `last_run` datetime, `cron_expr` varchar(1024) NOT NULL, `status` varchar(255), `user_id` int(11), `alert_keys` text, `deleted_at` datetime, `error_timeout` int(11) DEFAULT 60 NOT NULL, `next_run` datetime, `description` text, `app_id` int(11) NOT NULL, `metrics` text NOT NULL, `monitor_expr` text, `minutes` int(11), `to_date` text) ENGINE=InnoDB DEFAULT CHARSET=utf8
323
+  (10.0ms) CREATE INDEX `app_id` ON `jobs` (`app_id`)
324
+  (9.0ms) CREATE UNIQUE INDEX `id_name_version_key` ON `jobs` (`id`, `name`)
325
+  (12.0ms) CREATE INDEX `jobs_ibfk_1` ON `jobs` (`user_id`)
326
+  (10.0ms) CREATE TABLE `users` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `created_at` datetime, `updated_at` datetime, `encrypted_password` varchar(255) DEFAULT '' NOT NULL, `email` varchar(255) NOT NULL, `first_name` varchar(255), `last_name` varchar(255), `last_login` datetime, `preferences` text) ENGINE=InnoDB DEFAULT CHARSET=utf8
327
+  (9.0ms) CREATE UNIQUE INDEX `email` ON `users` (`email`)
328
+  (14.0ms) CREATE TABLE `schema_migrations` (`version` varchar(255) NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8
329
+  (10.0ms) CREATE UNIQUE INDEX `unique_schema_migrations` ON `schema_migrations` (`version`)
330
+  (2.0ms) SELECT version FROM `schema_migrations`
331
+  (2.0ms) INSERT INTO `schema_migrations` (version) VALUES ('20131106162900')