nosey 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -36,15 +36,18 @@ Instrument your Ruby app with nosey.
36
36
  nosey.touch 'started_at'
37
37
  end
38
38
 
39
- def growl
40
- nosey.increment 'growls'
41
- nosey.touch 'last_growled_at'
42
- "Grrrrr!"
39
+ def growl(volume=1)
40
+ nosey.touch 'last-growled-at'
41
+ nosey.increment 'growl-count'
42
+ nosey.avg 'growl-volume-avg', volume
43
+ nosey.min 'growl-volume-min', volume
44
+ nosey.max 'growl-volume-max', volume
45
+ "G#{'r' * volume}!"
43
46
  end
44
47
  end
45
48
 
46
49
  princess = PandaBear.new
47
- princess.growl
50
+ 10.times {|n| princess.growl rand * 5 }
48
51
  princess.nosey.report # Soon to be a fantastico report, prolly in YML
49
52
 
50
53
  When you fire Ruby this up, Nosey will open up a socket and report the stats.
data/lib/nosey/probe.rb CHANGED
@@ -26,52 +26,42 @@ module Nosey
26
26
  end
27
27
  end
28
28
 
29
- # Calulcates a min, max, and avg for a given number of samples
30
- class Sampler < Base
31
- attr_reader :min, :max, :sum, :count
32
-
33
- def initialize(*args)
34
- reset
35
- super(*args)
36
- end
37
-
29
+ class Average < Base
38
30
  def sample(value)
39
- @min = @max = value unless @min and @max
40
-
41
- @min = value if value < @min
42
- @max = value if value > @max
31
+ @sum ||= 0
32
+ @count ||= 0
43
33
  @sum += value
44
34
  @count += 1
45
-
46
- to_hash
47
35
  end
48
36
 
49
- def avg
50
- sum / count if count > 0 and sum
37
+ def value
38
+ @sum.to_f / @count.to_f if @sum and @count > 0
51
39
  end
40
+ end
52
41
 
53
- def to_hash
54
- {
55
- 'max' => max,
56
- 'min' => min,
57
- 'sum' => sum,
58
- 'avg' => avg,
59
- 'count' => count
60
- }
42
+ class Minimum < Base
43
+ def sample(value)
44
+ @value ||= value
45
+ @value = value if value < @value
61
46
  end
47
+ end
62
48
 
63
- def value
64
- to_hash
49
+ class Maximum < Base
50
+ def sample(value)
51
+ @value ||= value
52
+ @value = value if value > @value
65
53
  end
54
+ end
66
55
 
67
- def reset
68
- @min = @max = nil
69
- @sum = @count = 0
56
+ class Sum < Base
57
+ def sample(value)
58
+ @value ||= 0
59
+ @value += value
70
60
  end
71
61
  end
72
62
 
73
63
  # Count up/down values.
74
- class Counter < Base
64
+ class Count < Base
75
65
  def increment(by=1)
76
66
  change by
77
67
  end
@@ -96,7 +86,7 @@ module Nosey
96
86
 
97
87
  # Contains a collection of probes that calculate velocities, counts, etc.
98
88
  class Probe::Set
99
- attr_reader :name
89
+ attr_accessor :name
100
90
 
101
91
  def initialize(name)
102
92
  @name = name
@@ -106,17 +96,17 @@ module Nosey
106
96
 
107
97
  # Increment a counter probe
108
98
  def increment(key,by=1)
109
- ensure_probe(Probe::Counter, key).increment(by)
99
+ ensure_probe(Probe::Count, key).increment(by)
110
100
  end
111
101
 
112
102
  # Decrement a counter probe
113
103
  def decrement(key,by=1)
114
- ensure_probe(Probe::Counter, key).decrement(by)
104
+ ensure_probe(Probe::Count, key).decrement(by)
115
105
  end
116
106
 
117
107
  # Sample a number and get a sum/avg/count/min/max
118
- def sample(key,val)
119
- ensure_probe(Probe::Sampler, key).sample(val)
108
+ def avg(key,val)
109
+ ensure_probe(Probe::Average, key).sample(val)
120
110
  end
121
111
 
122
112
  # Touch a timestamp probe
@@ -124,6 +114,22 @@ module Nosey
124
114
  ensure_probe(Probe::Touch, key).touch
125
115
  end
126
116
 
117
+ def min(key,value)
118
+ ensure_probe(Probe::Minimum, key).sample(value)
119
+ end
120
+
121
+ def max(key,value)
122
+ ensure_probe(Probe::Maximum, key).sample(value)
123
+ end
124
+
125
+ def avg(key,value)
126
+ ensure_probe(Probe::Average, key).sample(value)
127
+ end
128
+
129
+ def sum(key,value)
130
+ ensure_probe(Probe::Sum, key).sample(value)
131
+ end
132
+
127
133
  # List of all the probes that are active
128
134
  def probes
129
135
  @probes ||= Hash.new
data/lib/nosey/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nosey
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -7,7 +7,10 @@ describe Nosey::Munin::Graph do
7
7
  r.probe_sets << Nosey::Probe::Set.new("Group #{n}") do |s|
8
8
  s.touch 'generated-at'
9
9
  s.increment 'hit'
10
- s.sample 'chopper', 2
10
+ s.avg 'chopper-avg', 2
11
+ s.min 'chopper-min', 2
12
+ s.max 'chopper-max', 2
13
+ s.sum 'chopper-sum', 2
11
14
  end
12
15
  end
13
16
  end
@@ -36,7 +39,7 @@ describe Nosey::Munin::Graph do
36
39
  end
37
40
 
38
41
  it "should have labels" do
39
- @text.scan(/[A-Za-z0-9_]+\.label .+\n/).should have(7).items
42
+ @text.scan(/[A-Za-z0-9_]+\.label .+\n/).should have(6).items
40
43
  end
41
44
  end
42
45
 
@@ -46,7 +49,7 @@ describe Nosey::Munin::Graph do
46
49
  end
47
50
 
48
51
  it "should have values" do
49
- @text.scan(/[A-Za-z0-9_]+\.value .+\n/).should have(7).items
52
+ @text.scan(/[A-Za-z0-9_]+\.value .+\n/).should have(6).items
50
53
  end
51
54
  end
52
55
  end
@@ -21,8 +21,20 @@ describe Nosey::Probe::Set do
21
21
  @probes.touch('touched-at').should be_instance_of(Time)
22
22
  end
23
23
 
24
- it "should sample" do
25
- @probes.sample('foobers', 1).should be_instance_of(Hash)
24
+ it "should avg" do
25
+ @probes.avg('foobers', 1)
26
+ end
27
+
28
+ it "should sum" do
29
+ @probes.sum('foobers', 1)
30
+ end
31
+
32
+ it "should max" do
33
+ @probes.max('foobers', 1)
34
+ end
35
+
36
+ it "should min" do
37
+ @probes.max('foobers', 1)
26
38
  end
27
39
 
28
40
  it "should get probe" do
@@ -35,9 +47,39 @@ describe Nosey::Probe::Set do
35
47
  end
36
48
  end
37
49
 
38
- describe Nosey::Probe::Counter do
50
+ describe Nosey::Probe do
51
+ it "should calculate sum" do
52
+ sum = Nosey::Probe::Sum.new
53
+ sum.sample(1)
54
+ sum.sample(2)
55
+ sum.value.should eql(3)
56
+ end
57
+
58
+ it "should calculate max" do
59
+ max = Nosey::Probe::Maximum.new
60
+ max.sample(1)
61
+ max.sample(3)
62
+ max.value.should eql(3)
63
+ end
64
+
65
+ it "should calculate minimum" do
66
+ min = Nosey::Probe::Minimum.new
67
+ min.sample(1)
68
+ min.sample(2)
69
+ min.value.should eql(1)
70
+ end
71
+
72
+ it "should calculate average" do
73
+ avg = Nosey::Probe::Average.new
74
+ avg.sample(1)
75
+ avg.sample(2)
76
+ avg.value.should eql(1.5)
77
+ end
78
+ end
79
+
80
+ describe Nosey::Probe::Count do
39
81
  before(:all) do
40
- @counter = Nosey::Probe::Counter.new
82
+ @counter = Nosey::Probe::Count.new
41
83
  end
42
84
 
43
85
  it "should init null" do
@@ -69,37 +111,4 @@ describe Nosey::Probe::Touch do
69
111
  @touch.touch
70
112
  @touch.value.should_not be_nil
71
113
  end
72
- end
73
-
74
- describe Nosey::Probe::Sampler do
75
- before(:each) do
76
- @counter = Nosey::Probe::Sampler.new
77
- @counter.sample 1
78
- @counter.sample 2
79
- @counter.sample 3
80
- end
81
-
82
- it "should init hash" do
83
- @counter.value.should be_instance_of(Hash)
84
- end
85
-
86
- it "should have avg" do
87
- @counter.value['avg'].should eql(2)
88
- end
89
-
90
- it "should have sum" do
91
- @counter.value['sum'].should eql(6)
92
- end
93
-
94
- it "should have min" do
95
- @counter.value['min'].should eql(1)
96
- end
97
-
98
- it "should have max" do
99
- @counter.value['max'].should eql(3)
100
- end
101
-
102
- it "should have count" do
103
- @counter.value['count'].should eql(3)
104
- end
105
114
  end
@@ -9,7 +9,7 @@ describe EventMachine::Nosey::SocketServer do
9
9
  r.probe_sets << Nosey::Probe::Set.new("Group #{n}") do |set|
10
10
  set.increment 'hit'
11
11
  set.touch 'generated-at'
12
- set.sample 'zie-number', 1
12
+ set.avg 'zie-number-avg', 1
13
13
  end
14
14
  end
15
15
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Brad Gessler
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-09-14 00:00:00 -07:00
17
+ date: 2011-09-15 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency