Permalink
Browse files

can run every minute; respects checkin directive from server and --fo…

…rce argument from user
  • Loading branch information...
1 parent 10feb03 commit 53e1113bdcb5ff57ffc6c0dc300aa85299eeb7d7 Andre Lewis committed Nov 24, 2009
Showing with 283 additions and 148 deletions.
  1. +2 −1 .gitignore
  2. +41 −41 Rakefile
  3. +25 −20 lib/scout/command.rb
  4. +2 −0 lib/scout/command/install.rb
  5. +11 −2 lib/scout/command/run.rb
  6. +2 −0 lib/scout/command/test.rb
  7. +93 −84 lib/scout/server.rb
  8. +86 −0 test/plugins/disk_usage.rb
  9. +21 −0 test/scout_test.rb
View
@@ -1,4 +1,5 @@
doc/*
pkg/*
.DS_Store
-**/.DS_Store
+**/.DS_Store
+.idea
View
@@ -7,8 +7,8 @@ require "net/ssh"
require "rubygems"
require "rubyforge"
-dir = File.dirname(__FILE__)
-lib = File.join(dir, "lib", "scout.rb")
+dir = File.dirname(__FILE__)
+lib = File.join(dir, "lib", "scout.rb")
version = File.read(lib)[/^\s*VERSION\s*=\s*(['"])(\d\.\d\.\d)\1/, 2]
history = File.read("CHANGELOG").split(/^(===.*)/)
changes ||= history[0..2].join.strip
@@ -19,59 +19,59 @@ need_zip = true
task :default => [:test]
Rake::TestTask.new do |test|
- test.libs << "test"
+ test.libs << "test"
test.test_files = [ "test/scout_test.rb" ]
- test.verbose = true
+ test.verbose = true
end
Rake::RDocTask.new do |rdoc|
- rdoc.main = "README"
- rdoc.rdoc_dir = "doc/html"
- rdoc.title = "Scout Client Documentation"
- rdoc.rdoc_files.include( "README", "INSTALL",
- "TODO", "CHANGELOG",
- "AUTHORS", "COPYING",
- "LICENSE", "lib/" )
+ rdoc.main = "README"
+ rdoc.rdoc_dir = "doc/html"
+ rdoc.title = "Scout Client Documentation"
+ rdoc.rdoc_files.include( "README", "INSTALL",
+ "TODO", "CHANGELOG",
+ "AUTHORS", "COPYING",
+ "LICENSE", "lib/" )
end
spec = Gem::Specification.new do |spec|
- spec.name = "scout"
- spec.version = version
+ spec.name = "scout"
+ spec.version = version
- spec.platform = Gem::Platform::RUBY
- spec.summary = "Scout makes monitoring and reporting on your web applications as flexible and simple as possible."
+ spec.platform = Gem::Platform::RUBY
+ spec.summary = "Scout makes monitoring and reporting on your web applications as flexible and simple as possible."
# TODO: test suite
- # spec.test_suite_file = "test/ts_all.rb"
- spec.files = Dir.glob("{bin,lib}/**/*.rb") +
- Dir.glob("{data,vendor}/**/*") +
- %w[Rakefile]
- spec.executables = ["scout"]
-
- spec.has_rdoc = true
- spec.extra_rdoc_files = %w[ AUTHORS COPYING README INSTALL TODO CHANGELOG
+ # spec.test_suite_file = "test/ts_all.rb"
+ spec.files = Dir.glob("{bin,lib}/**/*.rb") +
+ Dir.glob("{data,vendor}/**/*") +
+ %w[Rakefile]
+ spec.executables = ["scout"]
+
+ spec.has_rdoc = true
+ spec.extra_rdoc_files = %w[ AUTHORS COPYING README INSTALL TODO CHANGELOG
LICENSE ]
- spec.rdoc_options << "--title" << "Scout Client Documentation" <<
- "--main" << "README"
+ spec.rdoc_options << "--title" << "Scout Client Documentation" <<
+ "--main" << "README"
+
+ spec.require_path = "lib"
- spec.require_path = "lib"
-
spec.add_dependency "elif"
- spec.author = "Highgroove Studios"
- spec.email = "scout@highgroove.com"
- spec.rubyforge_project = "scout"
- spec.homepage = "http://scoutapp.com"
- spec.description = <<END_DESC
+ spec.author = "Highgroove Studios"
+ spec.email = "scout@highgroove.com"
+ spec.rubyforge_project = "scout"
+ spec.homepage = "http://scoutapp.com"
+ spec.description = <<END_DESC
Scout makes monitoring and reporting on your web applications as flexible and simple as possible.
Scout is a product of Highgroove Studios.
END_DESC
end
Rake::GemPackageTask.new(spec) do |pkg|
- pkg.need_zip = need_tar
- pkg.need_tar = need_zip
+ pkg.need_zip = need_tar
+ pkg.need_tar = need_zip
end
desc "Publishes to Scout Gem Server and Rubyforge"
@@ -85,22 +85,22 @@ task :publish_rubyforge => [:package] do
puts "Logging in"
forge.login
- release = forge.userconfig
+ release = forge.userconfig
release["release_changes"] = File.read(File.join(dir, "CHANGELOG"))
- release["preformatted"] = true
+ release["preformatted"] = true
package = "pkg/#{spec.name}-#{version}"
- files = %W[#{package}.tgz #{package}.zip #{package}.gem].compact
+ files = %W[#{package}.tgz #{package}.zip #{package}.gem].compact
puts "Releasing #{spec.name}-#{version}"
forge.add_release(spec.rubyforge_project, spec.name, version, *files)
end
desc "Upload current documentation to Scout Gem Server and RubyForge"
task :upload_docs => [:rdoc] do
- sh "scp -r doc/html/* " +
- "deploy@gems.scoutapp.com:/var/www/gems/docs"
-
+ sh "scp -r doc/html/* " +
+ "deploy@gems.scoutapp.com:/var/www/gems/docs"
+
config = YAML.load(File.read(File.expand_path("~/.rubyforge/user-config.yml")))
host = "#{config["username"]}@rubyforge.org"
@@ -112,5 +112,5 @@ end
desc "Add new files to Subersion"
task :svn_add do
- system "svn status | grep '^\?' | sed -e 's/? *//' | sed -e 's/ /\ /g' | xargs svn add"
+ system "svn status | grep '^\?' | sed -e 's/? *//' | sed -e 's/ /\ /g' | xargs svn add"
end
View
@@ -9,15 +9,15 @@ class Command
def self.user
@user ||= ENV["USER"] || ENV["USERNAME"] || "root"
end
-
+
def self.program_name
@program_name ||= File.basename($PROGRAM_NAME)
end
def self.program_path
@program_path ||= File.expand_path($PROGRAM_NAME)
end
-
+
def self.usage
@usage
end
@@ -89,13 +89,17 @@ def self.parse_options(argv)
"Turn on logging to STDOUT" ) do |bool|
options[:verbose] = bool
end
-
+
opts.on( "-V", "--version",
"Display the current version") do |version|
puts Scout::VERSION
exit
end
+ opts.on( "-F", "--force", "Force checkin to Scout server regardless of last checkin time") do |bool|
+ options[:force] = bool
+ end
+
begin
opts.parse!
@usage = opts.to_s
@@ -104,26 +108,26 @@ def self.parse_options(argv)
exit
end
end
-
+
options
end
private_class_method :parse_options
-
+
def self.dispatch(argv)
options = parse_options(argv)
command = if name_or_key = argv.shift
- if cls = Scout::Command.const_get(name_or_key.capitalize) \
- rescue nil
+ if cls = (Scout::Command.const_get(name_or_key.capitalize) rescue nil)
cls.new(options, argv)
else
Run.new(options, [name_or_key] + argv)
end
else
Install.new(options, argv)
end
- command.create_pid_file_or_exit.run
+
+ command.run
end
-
+
def initialize(options, args)
@server = options[:server] || "https://scoutapp.com/"
@history = options[:history] ||
@@ -132,23 +136,24 @@ def initialize(options, args)
"client_history.yaml" )
@verbose = options[:verbose] || false
@level = options[:level] || "info"
-
+ @force = options[:force] || false
+
@args = args
end
-
+
attr_reader :server, :history
-
+
def config_dir
return @config_dir if defined? @config_dir
@config_dir = File.dirname(history)
FileUtils.mkdir_p(@config_dir) # ensure dir exists
@config_dir
end
-
+
def verbose?
@verbose
end
-
+
def log
return @log if defined? @log
@log = if verbose?
@@ -160,27 +165,27 @@ def log
nil
end
end
-
+
def level
Logger.const_get(@level.upcase) rescue Logger::INFO
end
-
+
def user
@user ||= Command.user
end
-
+
def program_name
@program_name ||= Command.program_name
end
def program_path
@program_path ||= Command.program_path
end
-
+
def usage
@usage ||= Command.usage
end
-
+
def create_pid_file_or_exit
pid_file = File.join(config_dir, "scout_client_pid.txt")
begin
@@ -228,7 +233,7 @@ def create_pid_file_or_exit
retry
end
end
-
+
self
end
end
@@ -4,6 +4,8 @@ module Scout
class Command
class Install < Command
def run
+ create_pid_file_or_exit
+
abort usage unless $stdin.tty?
puts <<-END_INTRO.gsub(/^ {8}/, "")
View
@@ -3,10 +3,19 @@
module Scout
class Command
class Run < Command
+ # for this command, you must call prepare before calling run
def run
key = @args.first
- Scout::Server.new(server, key, history, log) do |scout|
- scout.run_plugins_by_plan
+ @scout = Scout::Server.new(server, key, history, log)
+ @scout.load_history
+ @scout.fetch_plan
+
+ if @scout.checkin_now || @force
+ create_pid_file_or_exit
+ @scout.run_plugins_by_plan
+ @scout.save_history
+ else
+ log.info "Not time to checkin yet" if log
end
end
end
@@ -6,6 +6,8 @@ module Scout
class Command
class Test < Command
def run
+ create_pid_file_or_exit
+
plugin, options = @args
# read the plugin_code from the file specified
Oops, something went wrong.

0 comments on commit 53e1113

Please sign in to comment.