redmon 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -42,6 +42,7 @@ $ redmon -h
42
42
  Usage: /Users/sean/codez/steelThread/redmon/vendor/ruby/1.9.1/bin/redmon (options)
43
43
  -a, --address ADDRESS The thin bind address for the app (default: 0.0.0.0)
44
44
  -n, --namespace NAMESPACE The root Redis namespace (default: redmon)
45
+ -l, --lifespan MINUTES Lifespan(in minutes) for polled data (default: 30)
45
46
  -i, --interval SECS Poll interval in secs for the worker (default: 10)
46
47
  -p, --port PORT The thin bind port for the app (default: 4567)
47
48
  -r, --redis URL The Redis url for monitor (default: redis://127.0.0.1:6379)
data/bin/redmon CHANGED
@@ -46,6 +46,13 @@ class RedmonCLI
46
46
  :description => 'Poll interval in secs for the worker (default: 10)',
47
47
  :proc => to_i
48
48
 
49
+ option :data_lifespan,
50
+ :short => '-l MINUTES',
51
+ :long => '--lifespan MINUTES',
52
+ :default => 30,
53
+ :description => 'Lifespan(in minutes) for polled data (default: 30)',
54
+ :proc => to_i
55
+
49
56
  option :app,
50
57
  :on => :tail,
51
58
  :long => '--no-app',
data/lib/redmon.rb CHANGED
@@ -10,6 +10,7 @@ module Redmon
10
10
  rescue Exception => e
11
11
  unless e.is_a?(SystemExit)
12
12
  log "!!! Redmon has shit the bed, restarting... #{e.message}"
13
+ e.backtrace.each { |line| log line }
13
14
  sleep(1)
14
15
  run(opts)
15
16
  end
data/lib/redmon/app.rb CHANGED
@@ -7,6 +7,9 @@ module Redmon
7
7
 
8
8
  helpers Redmon::Helpers
9
9
 
10
+ set :root, File.dirname(__FILE__)
11
+ set :views, Proc.new { File.join(root, "./views") }
12
+
10
13
  use Rack::Static, {
11
14
  :urls => [/\.css$/, /\.js$/],
12
15
  :root => "#{root}/public",
@@ -53,4 +56,4 @@ module Redmon
53
56
  end
54
57
 
55
58
  end
56
- end
59
+ end
data/lib/redmon/config.rb CHANGED
@@ -15,6 +15,7 @@ module Redmon
15
15
  :worker => true,
16
16
  :web_interface => ['0.0.0.0', 4567],
17
17
  :poll_interval => 10,
18
+ :data_lifespan => 30,
18
19
  :secure => false
19
20
  }
20
21
 
@@ -10,6 +10,10 @@ module Redmon
10
10
  Redmon.config.poll_interval * 1000
11
11
  end
12
12
 
13
+ def num_samples_to_request
14
+ (Redmon.config.data_lifespan * 60) / Redmon.config.poll_interval
15
+ end
16
+
13
17
  def count
14
18
  -(params[:count] ? params[:count].to_i : 1)
15
19
  end
@@ -3,13 +3,13 @@ var Redmon = (function() {
3
3
  , events = $({});
4
4
 
5
5
  /**
6
- * Loads the last 100 events and starts the periodic polling for new events.
6
+ * Loads the last numSamples events and starts the periodic polling for new events.
7
7
  */
8
8
  function init(opts) {
9
9
  config = opts;
10
10
  toolbar.init();
11
11
  cli.init();
12
- requestData(100, function(data) {
12
+ requestData(config.numSamples, function(data) {
13
13
  renderDashboard(data);
14
14
  poll();
15
15
  });
@@ -1,3 +1,3 @@
1
1
  module Redmon
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -167,6 +167,7 @@
167
167
  $(document).ready(function() {
168
168
  Redmon.init({
169
169
  pollInterval : #{poll_interval},
170
+ numSamples : #{num_samples_to_request},
170
171
  cliPrompt : '#{prompt}',
171
172
  absoluteUrl : '#{absolute_url}'
172
173
  });
data/lib/redmon/worker.rb CHANGED
@@ -3,13 +3,22 @@ module Redmon
3
3
  include Redmon::Redis
4
4
 
5
5
  def run!
6
- EM::PeriodicTimer.new(interval) {record_stats}
6
+ EM::PeriodicTimer.new(interval) {
7
+ record_stats
8
+ cleanup_old_stats
9
+ }
7
10
  end
8
11
 
9
12
  def record_stats
10
13
  redis.zadd stats_key, *stats
11
14
  end
12
15
 
16
+ def cleanup_old_stats
17
+ # When indexing from the end of a sorted set, we start at -1, so we need to add 1 here or we'll be keeping one
18
+ # fewer samples than expected
19
+ redis.zremrangebyscore stats_key, '-inf', '(' + oldest_data_to_keep.to_s
20
+ end
21
+
13
22
  def stats
14
23
  stats = redis.info.merge! \
15
24
  :dbsize => redis.dbsize,
@@ -37,5 +46,14 @@ module Redmon
37
46
  Redmon.config.poll_interval
38
47
  end
39
48
 
49
+ def data_lifespan
50
+ Redmon.config.data_lifespan
51
+ end
52
+
53
+ def oldest_data_to_keep
54
+ lifespan_seconds = data_lifespan * 60
55
+ oldest_time_to_keep = Time.now - lifespan_seconds
56
+ oldest_time_to_keep.to_i * 1000
57
+ end
40
58
  end
41
59
  end
data/spec/helpers_spec.rb CHANGED
@@ -1,4 +1,7 @@
1
1
  require 'spec_helper'
2
+ require 'redmon/helpers'
3
+
4
+ include Redmon::Helpers
2
5
 
3
6
  describe "Helpers" do
4
7
 
@@ -83,4 +86,13 @@ describe "Helpers" do
83
86
  end
84
87
  end
85
88
 
89
+ describe "#num_samples_to_request" do
90
+ it "should return the number of samples to request based on poll interval and data lifespan" do
91
+ Redmon.config.stub(:data_lifespan).and_return(31)
92
+ Redmon.config.stub(:poll_interval).and_return(10)
93
+
94
+ num_samples_to_request.should == (31 * 60) / 10
95
+ end
96
+ end
97
+
86
98
  end
data/spec/worker_spec.rb CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe "worker" do
4
4
 
5
- before(:all) do
5
+ before(:each) do
6
6
  @worker = Redmon::Worker.new
7
7
  end
8
8
 
@@ -24,6 +24,14 @@ describe "worker" do
24
24
  end
25
25
  end
26
26
 
27
+ describe "#cleanup_old_stats" do
28
+ it "should remove old stats entries from a redis sorted set" do
29
+ redis = mock_redis
30
+ redis.should_receive(:zremrangebyscore).with(Redmon::Redis.stats_key, '-inf', '(' + @worker.oldest_data_to_keep.to_s)
31
+ @worker.cleanup_old_stats
32
+ end
33
+ end
34
+
27
35
  describe "#stats" do
28
36
  it "should fetch info, dbsize and slowlog from redis" do
29
37
  pending
@@ -59,4 +67,19 @@ describe "worker" do
59
67
  end
60
68
  end
61
69
 
70
+ describe "#data_lifespan" do
71
+ it "should return the data lifspan" do
72
+ @worker.data_lifespan.should == Redmon.config.data_lifespan
73
+ end
74
+ end
75
+
76
+ describe "#oldest_data_to_keep" do
77
+ it "should return the oldest data timestamp that should be kept" do
78
+ Time.stub(:now).and_return(Time.at(1366044862))
79
+ @worker.stub(:data_lifespan).and_return(30)
80
+
81
+ @worker.oldest_data_to_keep.should == 1366043062000
82
+ end
83
+ end
84
+
62
85
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redmon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-15 00:00:00.000000000 Z
12
+ date: 2013-05-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bson_ext
@@ -305,18 +305,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
305
305
  - - ! '>='
306
306
  - !ruby/object:Gem::Version
307
307
  version: '0'
308
- segments:
309
- - 0
310
- hash: -3799248200980618654
311
308
  required_rubygems_version: !ruby/object:Gem::Requirement
312
309
  none: false
313
310
  requirements:
314
311
  - - ! '>='
315
312
  - !ruby/object:Gem::Version
316
313
  version: '0'
317
- segments:
318
- - 0
319
- hash: -3799248200980618654
320
314
  requirements: []
321
315
  rubyforge_project: redmon
322
316
  rubygems_version: 1.8.23