Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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...
commit 1fd157ecf8ac8e43c25c5e24a6dcebdedec1af56 1 parent 393c387
@jamis jamis authored
View
3  ChangeLog
@@ -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
2  Rakefile
@@ -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"
View
23 lib/switchtower/ext/monitor.rb
@@ -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,11 +127,17 @@ 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 }
@@ -129,11 +145,6 @@ def requests_per_second(*logs)
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
View
2  lib/switchtower/ext/version.rb
@@ -3,7 +3,7 @@ module Ext
module Version #:nodoc:
MAJOR = 1
MINOR = 0
- TINY = 0
+ TINY = 1
STRING = [MAJOR, MINOR, TINY].join(".")
end
View
1  switchtower-ext.gemspec
@@ -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"
Please sign in to comment.
Something went wrong with that request. Please try again.