Permalink
Browse files

Make watch_requests friendly to multiple users

git-svn-id: http://svn.jamisbuck.org/projects/switchtower-ext@6 e3b5881a-3c0d-0410-9405-fd48df27f097
  • Loading branch information...
jamis committed Feb 22, 2006
1 parent 393c387 commit 1fd157ecf8ac8e43c25c5e24a6dcebdedec1af56
Showing with 23 additions and 8 deletions.
  1. +3 −0 ChangeLog
  2. +1 −1 Rakefile
  3. +17 −6 lib/switchtower/ext/monitor.rb
  4. +1 −1 lib/switchtower/ext/version.rb
  5. +1 −0 switchtower-ext.gemspec
View
@@ -0,0 +1,3 @@
+*1.0.1* *SVN*
+
+* Put request monitor script in user's home directory, instead of /tmp, to accomodate multiple users
View
@@ -18,7 +18,7 @@ Rake::GemPackageTask.new(GEM_SPEC) do |p|
p.gem_spec = GEM_SPEC
p.need_tar = true
p.need_zip = true
- p.package_files.include 'README', 'MIT-LICENSE', 'setup.rb'
+ p.package_files.include 'README', 'MIT-LICENSE', 'setup.rb', 'ChangeLog'
end
desc "Build the RDoc API documentation"
@@ -44,6 +44,16 @@ def headers(*args)
puts
end
+ # Get a value from the remote environment
+ def remote_env(value)
+ result = ""
+ run("echo $#{value}", :once => true) do |ch, stream, data|
+ raise "could not get environment variable #{value}: #{data}" if stream == :err
+ result << data
+ end
+ result.chomp
+ end
+
# Monitor the load of the servers tied to the current task.
def load(options={})
servers = current_task.servers.sort
@@ -117,23 +127,24 @@ def requests_per_second(*logs)
minute_5 = 300 / sample_size
minute_15 = 900 / sample_size
+ # store our helper script on the servers. This script reduces the amount
+ # of traffic caused by tailing busy logs across the network, and also reduces
+ # the amount of work the client has to do.
+ script = "#{remote_env("HOME")}/x-request-counter.rb"
+ put_asset "request-counter.rb", script
+
# set up (but don't start) the runner thread, which accumulates request
# counts from the servers.
runner = Thread.new do Thread.stop
running = true
- run("echo 0 && tail -F #{logs.join(" ")} | ruby /tmp/request-counter.rb '#{request_pattern}'") do |ch, stream, out|
+ run("echo 0 && tail -F #{logs.join(" ")} | ruby #{script} '#{request_pattern}'") do |ch, stream, out|
channels[ch[:host]] ||= ch
puts "#{ch[:host]}: #{out}" and break if stream == :err
mutex.synchronize { count[ch[:host]] += out.to_i }
end
running = false
end
- # store our helper script on the servers. This script reduces the amount
- # of traffic caused by tailing busy logs across the network, and also reduces
- # the amount of work the client has to do.
- put_asset "request-counter.rb", "/tmp/request-counter.rb"
-
# let the runner thread get started
runner.wakeup
sleep 0.01 while !running
@@ -3,7 +3,7 @@ module Ext
module Version #:nodoc:
MAJOR = 1
MINOR = 0
- TINY = 0
+ TINY = 1
STRING = [MAJOR, MINOR, TINY].join(".")
end
View
@@ -11,6 +11,7 @@ Gem::Specification.new do |s|
DESC
s.files = Dir.glob("lib/**/*")
+ s.files << 'ChangeLog' << 'README' << 'MIT-LICENSE'
s.require_path = 'lib'
s.add_dependency 'switchtower', ">= 1.0.0"

0 comments on commit 1fd157e

Please sign in to comment.