dj-monitor 0.0.0.1.beta
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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/README.textile +60 -0
- data/Rakefile +2 -0
- data/bin/dj-monitor +13 -0
- data/dj-monitor.gemspec +21 -0
- data/lib/dj-monitor/monitor.rb +134 -0
- data/lib/dj-monitor/railtie.rb +11 -0
- data/lib/dj-monitor/version.rb +3 -0
- data/lib/dj-monitor.rb +6 -0
- metadata +90 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.textile
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
h1. DJ Monitor
|
2
|
+
|
3
|
+
This gem is meant to monitor a DJ Work queue. Right now its a work in progress and only works for me. Some config options need to be extracted as of yet (defaults to mine)
|
4
|
+
|
5
|
+
h2. More Information
|
6
|
+
|
7
|
+
Not right now.
|
8
|
+
|
9
|
+
h2. Required Gems
|
10
|
+
|
11
|
+
This gem requires these gems:
|
12
|
+
|
13
|
+
* pony
|
14
|
+
* sequel
|
15
|
+
|
16
|
+
h2. Dependencies
|
17
|
+
|
18
|
+
To use this gem, you will need:
|
19
|
+
|
20
|
+
* The Ruby language (version 1.8.7 or 1.9.2)
|
21
|
+
* it need to be run for the rails root of your app
|
22
|
+
|
23
|
+
h2. Installing the gem
|
24
|
+
|
25
|
+
* gem install dj-monitor
|
26
|
+
|
27
|
+
h2. Getting Started
|
28
|
+
|
29
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
30
|
+
|
31
|
+
h2. Documentation and Support
|
32
|
+
|
33
|
+
This is the only documentation.
|
34
|
+
|
35
|
+
h4. Issues
|
36
|
+
|
37
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
38
|
+
|
39
|
+
h2. Similar Projects
|
40
|
+
|
41
|
+
* This project is based on *delayed_job-monitor* from *Michael Guterl*. Thanks!
|
42
|
+
|
43
|
+
h2. Contributing
|
44
|
+
|
45
|
+
If you make improvements to this application, please share with others.
|
46
|
+
|
47
|
+
* Make your feature addition or bug fix.
|
48
|
+
* Make a test for it!
|
49
|
+
* Commit with Git.
|
50
|
+
* Send the author message.
|
51
|
+
|
52
|
+
If you add functionality to this application, create an alternative implementation, or build an application that is similar, please contact me and I'll add a note to the README so that others can find your work.
|
53
|
+
|
54
|
+
h2. Credits
|
55
|
+
|
56
|
+
This project is based on *delayed_job-monitor* from *Michael Guterl*. Thanks!
|
57
|
+
|
58
|
+
h2. License
|
59
|
+
|
60
|
+
None
|
data/Rakefile
ADDED
data/bin/dj-monitor
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# assumes the cwd is a rails application
|
4
|
+
|
5
|
+
require 'yaml'
|
6
|
+
require 'rubygems'
|
7
|
+
require 'dj-monitor'
|
8
|
+
|
9
|
+
rails_env = ENV['RAILS_ENV'] || 'development'
|
10
|
+
STDOUT.puts "Loading #{rails_env}"
|
11
|
+
configuration = YAML.load_file("config/database.yml")
|
12
|
+
STDOUT.puts "Monitoring DJ in #{configuration[rails_env]['database']}"
|
13
|
+
Monitor.run(:database => configuration[rails_env])
|
data/dj-monitor.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/dj-monitor/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["David Westerink"]
|
6
|
+
gem.email = ["davidakachaos@gmail.com"]
|
7
|
+
gem.description = %q{Monitors the status of your Delayed Jobs.}
|
8
|
+
gem.summary = %q{This project is based on delayed_job-monitor from Michael Guterl. Thanks!}
|
9
|
+
gem.homepage = "https://github.com/davidakachaos/DJMonitor"
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "dj-monitor"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Djmonitor::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency "rspec"
|
19
|
+
gem.add_dependency(%q<sequel>, ["~> 3.12.1"])
|
20
|
+
gem.add_dependency(%q<pony>, ["~> 1.0.0"])
|
21
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'sequel'
|
2
|
+
require 'pony'
|
3
|
+
|
4
|
+
class Monitor
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def run(options)
|
9
|
+
Monitor.new(options).run
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_accessor :default_table_name
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
DEFAULT_TABLE_NAME = "delayed_jobs".freeze
|
17
|
+
|
18
|
+
self.default_table_name = DEFAULT_TABLE_NAME
|
19
|
+
|
20
|
+
attr_reader :table_name
|
21
|
+
|
22
|
+
DEFAULT_THRESHOLDS = {
|
23
|
+
:total_job_threshold => 50,
|
24
|
+
:failed_job_threshold => 1,
|
25
|
+
:scheduled_job_threshold => 40,
|
26
|
+
:waiting_job_threshold => 10,
|
27
|
+
:running_job_threshold => 5
|
28
|
+
}.freeze
|
29
|
+
|
30
|
+
THRESHOLD_ATTRIBUTES = DEFAULT_THRESHOLDS.keys
|
31
|
+
|
32
|
+
attr_accessor *THRESHOLD_ATTRIBUTES
|
33
|
+
|
34
|
+
def initialize(options)
|
35
|
+
@options = options
|
36
|
+
@db_options = @options[:database]
|
37
|
+
@table_name = @db_options.delete(:table_name) { Monitor.default_table_name }
|
38
|
+
|
39
|
+
# set thresholds, use default if not provided
|
40
|
+
DEFAULT_THRESHOLDS.each do |attribute, threshold|
|
41
|
+
send("#{attribute}=", options.delete(attribute) { threshold })
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def run
|
46
|
+
if sick?
|
47
|
+
alert
|
48
|
+
# else
|
49
|
+
# puts "All is fine!"
|
50
|
+
# puts "Total jobs:\t\t#{total_jobs}"
|
51
|
+
# puts "Failed jobs:\t\t#{failed_jobs}"
|
52
|
+
# puts "Scheduled jobs:\t\t#{scheduled_jobs}"
|
53
|
+
# puts "Waiting jobs:\t\t#{waiting_jobs}"
|
54
|
+
# puts "Running jobs:\t\t#{running_jobs}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def alert
|
59
|
+
Pony.mail(:to => @options[:alert_to] ? @options[:alert_to] : "dw@penthion.nl",
|
60
|
+
:from => @options[:alert_from] ? @options[:alert_from] : "monitor@penthion.nl",
|
61
|
+
:subject => @options[:alert_subject] ? @options[:alert_subject] : "[Alert] DJ Queue (#{@options[:database]})",
|
62
|
+
:body => alert_body)
|
63
|
+
end
|
64
|
+
|
65
|
+
def alert_body
|
66
|
+
%Q{
|
67
|
+
Delayed::Job Summary
|
68
|
+
--------------------
|
69
|
+
|
70
|
+
Total jobs:\t\t#{total_jobs}
|
71
|
+
Failed jobs:\t\t#{failed_jobs}
|
72
|
+
Scheduled jobs:\t\t#{scheduled_jobs}
|
73
|
+
Waiting jobs:\t\t#{waiting_jobs}
|
74
|
+
Running jobs:\t\t#{running_jobs}
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
78
|
+
def sick?
|
79
|
+
total_jobs >= total_job_threshold ||
|
80
|
+
failed_jobs >= failed_job_threshold ||
|
81
|
+
scheduled_jobs >= scheduled_job_threshold ||
|
82
|
+
waiting_jobs >= waiting_job_threshold ||
|
83
|
+
running_jobs >= running_job_threshold
|
84
|
+
end
|
85
|
+
|
86
|
+
def healthy?
|
87
|
+
!sick?
|
88
|
+
end
|
89
|
+
|
90
|
+
def reset
|
91
|
+
@total_jobs = nil
|
92
|
+
@scheduled_jobs = nil
|
93
|
+
@waiting_jobs = nil
|
94
|
+
@running_jobs = nil
|
95
|
+
@failed_jobs = nil
|
96
|
+
end
|
97
|
+
|
98
|
+
def total_jobs
|
99
|
+
@total_jobs ||= count
|
100
|
+
end
|
101
|
+
|
102
|
+
def scheduled_jobs
|
103
|
+
@scheduled_jobs ||= count(["run_at > ? AND locked_at IS NULL AND attempts = 0", Time.now])
|
104
|
+
end
|
105
|
+
|
106
|
+
def waiting_jobs
|
107
|
+
@waiting_jobs ||= count(["run_at <= ? AND locked_at IS NULL AND attempts = 0", Time.now])
|
108
|
+
end
|
109
|
+
|
110
|
+
def running_jobs
|
111
|
+
@running_jobs ||= count(["locked_at IS NOT NULL"])
|
112
|
+
end
|
113
|
+
|
114
|
+
def failed_jobs
|
115
|
+
@failed_jobs ||= count(["(run_at > ? AND last_error IS NOT NULL) OR failed_at IS NOT NULL", Time.now])
|
116
|
+
end
|
117
|
+
|
118
|
+
def count(filter = nil)
|
119
|
+
if filter
|
120
|
+
delayed_jobs.filter(filter).count
|
121
|
+
else
|
122
|
+
delayed_jobs.count
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def delayed_jobs
|
127
|
+
@delayed_jobs ||= database[table_name.to_sym]
|
128
|
+
end
|
129
|
+
|
130
|
+
def database
|
131
|
+
@database ||= Sequel.connect(@db_options)
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
module Delayed
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
initializer :after_initialize do
|
6
|
+
#Delayed::Worker.max_attempts = 3
|
7
|
+
#Delayed::Backend::ActiveRecord::Job.send(:include, Delayed::Workless::Scaler) if defined?(Delayed::Backend::ActiveRecord::Job)
|
8
|
+
#Delayed::Backend::Mongoid::Job.send(:include, Delayed::Workless::Scaler) if defined?(Delayed::Backend::Mongoid::Job)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/dj-monitor.rb
ADDED
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dj-monitor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0.1.beta
|
5
|
+
prerelease: 8
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- David Westerink
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-06 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &2153755540 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2153755540
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: sequel
|
27
|
+
requirement: &2153754580 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.12.1
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2153754580
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: pony
|
38
|
+
requirement: &2153740220 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.0.0
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2153740220
|
47
|
+
description: Monitors the status of your Delayed Jobs.
|
48
|
+
email:
|
49
|
+
- davidakachaos@gmail.com
|
50
|
+
executables:
|
51
|
+
- dj-monitor
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- Gemfile
|
57
|
+
- README.textile
|
58
|
+
- Rakefile
|
59
|
+
- bin/dj-monitor
|
60
|
+
- dj-monitor.gemspec
|
61
|
+
- lib/dj-monitor.rb
|
62
|
+
- lib/dj-monitor/monitor.rb
|
63
|
+
- lib/dj-monitor/railtie.rb
|
64
|
+
- lib/dj-monitor/version.rb
|
65
|
+
homepage: https://github.com/davidakachaos/DJMonitor
|
66
|
+
licenses: []
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>'
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.3.1
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.8.6
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: This project is based on delayed_job-monitor from Michael Guterl. Thanks!
|
89
|
+
test_files: []
|
90
|
+
has_rdoc:
|