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 +4 -4
- data/app/models/rearview/job.rb +0 -2
- data/app/models/rearview/job_error.rb +0 -2
- data/lib/rearview/alerts_handler.rb +0 -5
- data/lib/rearview/log_formatter.rb +40 -0
- data/lib/rearview/monitor_runner.rb +0 -4
- data/lib/rearview/monitor_supervisor.rb +0 -3
- data/lib/rearview/monitor_task.rb +6 -9
- data/lib/rearview/results_handler.rb +0 -3
- data/lib/rearview/stats_task.rb +4 -4
- data/lib/rearview/version.rb +1 -1
- data/lib/rearview.rb +13 -14
- data/spec/dummy/log/development.log +18 -0
- data/spec/dummy/log/test.log +2755 -0
- data/spec/lib/rearview/ext/numeric_spec.rb +16 -0
- data/spec/lib/rearview/log_formatter_spec.rb +13 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1801238546921f09bd33e3a81516867ff5a4d73e
|
4
|
+
data.tar.gz: a64de87d9f977c2fdc88d0e95450c630ca82dadf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a5aa2242148ddf22b6a5bd39b6c65f6e42acd9735d1acdf677ec91d7a227040dd10e246814ec4ce438b54d3c2e64fa22edfc3d2c4e164eb33343f52d7883299
|
7
|
+
data.tar.gz: 7e197973fdfa99f1cbf6fc511564d44af39950c10b2b93ea45d0f2a370fdc5fbe25f1677b8dc1178000db8c4f5d8cdbd44906cb1b75f1f47522b4a508b7d26d2
|
data/app/models/rearview/job.rb
CHANGED
@@ -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
|
@@ -4,16 +4,16 @@ module Rearview
|
|
4
4
|
class MonitorTask
|
5
5
|
class MonitorTaskError < StandardError; end;
|
6
6
|
include Celluloid
|
7
|
-
include
|
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
|
|
data/lib/rearview/stats_task.rb
CHANGED
@@ -4,7 +4,7 @@ module Rearview
|
|
4
4
|
class StatsTask
|
5
5
|
class StatsTaskError < StandardError; end;
|
6
6
|
include Celluloid
|
7
|
-
include
|
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
|
data/lib/rearview/version.rb
CHANGED
data/lib/rearview.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
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 "
|
57
|
-
logger.info "
|
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 "
|
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 "
|
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 "
|
70
|
+
logger.warn "monitor disabled!"
|
71
71
|
end
|
72
72
|
if config.stats_enabled?
|
73
|
-
logger.info "
|
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
|
[1m[35m (12.0ms)[0m CREATE UNIQUE INDEX `unique_schema_migrations` ON `schema_migrations` (`version`)
|
312
312
|
[1m[36m (1.0ms)[0m [1mSELECT version FROM `schema_migrations`[0m
|
313
313
|
[1m[35m (4.0ms)[0m INSERT INTO `schema_migrations` (version) VALUES ('20131106162900')
|
314
|
+
[1m[36m (20.0ms)[0m [1mDROP DATABASE IF EXISTS `rearview_ruby_test`[0m
|
315
|
+
[1m[35m (2.0ms)[0m CREATE DATABASE `rearview_ruby_test` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`
|
316
|
+
[1m[36m (39.0ms)[0m [1mCREATE 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[0m
|
317
|
+
[1m[35m (11.0ms)[0m CREATE INDEX `index_applications_on_ancestry` ON `applications` (`ancestry`)
|
318
|
+
[1m[36m (9.0ms)[0m [1mCREATE INDEX `user_id` ON `applications` (`user_id`)[0m
|
319
|
+
[1m[35m (8.0ms)[0m 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
|
+
[1m[36m (7.0ms)[0m [1mCREATE 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[0m
|
321
|
+
[1m[35m (9.0ms)[0m CREATE INDEX `job_id` ON `job_errors` (`job_id`)
|
322
|
+
[1m[36m (16.0ms)[0m [1mCREATE 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[0m
|
323
|
+
[1m[35m (10.0ms)[0m CREATE INDEX `app_id` ON `jobs` (`app_id`)
|
324
|
+
[1m[36m (9.0ms)[0m [1mCREATE UNIQUE INDEX `id_name_version_key` ON `jobs` (`id`, `name`)[0m
|
325
|
+
[1m[35m (12.0ms)[0m CREATE INDEX `jobs_ibfk_1` ON `jobs` (`user_id`)
|
326
|
+
[1m[36m (10.0ms)[0m [1mCREATE 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[0m
|
327
|
+
[1m[35m (9.0ms)[0m CREATE UNIQUE INDEX `email` ON `users` (`email`)
|
328
|
+
[1m[36m (14.0ms)[0m [1mCREATE TABLE `schema_migrations` (`version` varchar(255) NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8[0m
|
329
|
+
[1m[35m (10.0ms)[0m CREATE UNIQUE INDEX `unique_schema_migrations` ON `schema_migrations` (`version`)
|
330
|
+
[1m[36m (2.0ms)[0m [1mSELECT version FROM `schema_migrations`[0m
|
331
|
+
[1m[35m (2.0ms)[0m INSERT INTO `schema_migrations` (version) VALUES ('20131106162900')
|