diff options
author | Eric Wong <normalperson@yhbt.net> | 2011-09-27 17:46:20 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2011-09-27 19:51:19 -0700 |
commit | e974e26fcfb78cd579556495a0635d30ec5c6976 (patch) | |
tree | fec8faa7399d0e7b245bfff5f19f9fb59d923071 | |
parent | 9a42edb11efcd091623bb37a33a8ea97b39a1d85 (diff) | |
download | raindrops-e974e26fcfb78cd579556495a0635d30ec5c6976.tar.gz |
It can be useful to some to see that info all at once without hitting the HTML index page.
-rw-r--r-- | lib/raindrops/watcher.rb | 12 | ||||
-rw-r--r-- | test/test_watcher.rb | 21 |
2 files changed, 29 insertions, 4 deletions
diff --git a/lib/raindrops/watcher.rb b/lib/raindrops/watcher.rb index 66bc7b6..f343e43 100644 --- a/lib/raindrops/watcher.rb +++ b/lib/raindrops/watcher.rb @@ -172,14 +172,16 @@ class Raindrops::Watcher def active_stats(addr) # :nodoc: @lock.synchronize do tmp = @active[addr] or return - [ @snapshot[0], @resets[addr], tmp.dup ] + time, combined = @snapshot + [ time, @resets[addr], tmp.dup, combined[addr].active ] end end def queued_stats(addr) # :nodoc: @lock.synchronize do tmp = @queued[addr] or return - [ @snapshot[0], @resets[addr], tmp.dup ] + time, combined = @snapshot + [ time, @resets[addr], tmp.dup, combined[addr].queued ] end end @@ -204,9 +206,10 @@ class Raindrops::Watcher end def histogram_txt(agg) - updated_at, reset_at, agg = *agg + updated_at, reset_at, agg, current = *agg headers = agg_to_hash(reset_at, agg) body = agg.to_s + headers["X-Current"] = current.to_s headers["Content-Type"] = "text/plain" headers["Expires"] = (updated_at + @delay).httpdate headers["Content-Length"] = bytesize(body).to_s @@ -214,7 +217,7 @@ class Raindrops::Watcher end def histogram_html(agg, addr) - updated_at, reset_at, agg = *agg + updated_at, reset_at, agg, current = *agg headers = agg_to_hash(reset_at, agg) body = "<html>" \ "<head><title>#{hostname} - #{escape_html addr}</title></head>" \ @@ -225,6 +228,7 @@ class Raindrops::Watcher "<form action='/reset/#{escape addr}' method='post'>" \ "<input type='submit' name='x' value='reset' /></form>" \ "</body>" + headers["X-Current"] = current.to_s headers["Content-Type"] = "text/html" headers["Expires"] = (updated_at + @delay).httpdate headers["Content-Length"] = bytesize(body).to_s diff --git a/test/test_watcher.rb b/test/test_watcher.rb index 86c97d8..11a2d86 100644 --- a/test/test_watcher.rb +++ b/test/test_watcher.rb @@ -96,4 +96,25 @@ class TestWatcher < Test::Unit::TestCase break end end + + def test_x_current_header + env = @req.class.env_for "/active/#@addr.txt" + status, headers, body = @app.call(env) + assert_equal "0", headers["X-Current"], headers.inspect + + env = @req.class.env_for "/queued/#@addr.txt" + status, headers, body = @app.call(env) + assert_equal "1", headers["X-Current"], headers.inspect + + @ios << @srv.accept + sleep 0.1 + + env = @req.class.env_for "/queued/#@addr.txt" + status, headers, body = @app.call(env) + assert_equal "0", headers["X-Current"], headers.inspect + + env = @req.class.env_for "/active/#@addr.txt" + status, headers, body = @app.call(env) + assert_equal "1", headers["X-Current"], headers.inspect + end end if RUBY_PLATFORM =~ /linux/ |