cabin 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,4 +26,11 @@ class Cabin::Metrics::Counter
26
26
  def value
27
27
  return @lock.synchronize { @value }
28
28
  end # def value
29
+
30
+ public
31
+ def to_hash
32
+ return @lock.synchronize do
33
+ { :value => @value }
34
+ end
35
+ end # def to_hash
29
36
  end # class Cabin::Metrics::Counter
@@ -12,4 +12,9 @@ class Cabin::Metrics::Gauge
12
12
  def value
13
13
  return @block.call
14
14
  end # def value
15
+
16
+ public
17
+ def to_hash
18
+ return { :value => value }
19
+ end # def to_hash
15
20
  end # class Cabin::Metrics::Gauge
@@ -24,4 +24,11 @@ class Cabin::Metrics::Meter
24
24
  def value
25
25
  return @lock.synchronize { @value }
26
26
  end # def value
27
- end # class Cabin::Metrics::Counter
27
+
28
+ public
29
+ def to_hash
30
+ return @lock.synchronize do
31
+ { :value => @value }
32
+ end
33
+ end # def to_hash
34
+ end # class Cabin::Metrics::Meter
@@ -10,6 +10,7 @@ class Cabin::Metrics::Timer
10
10
  public
11
11
  def initialize
12
12
  @invocations = 0
13
+ @total_duration = 0.0
13
14
  @lock = Mutex.new
14
15
  end # def initialize
15
16
 
@@ -35,9 +36,10 @@ class Cabin::Metrics::Timer
35
36
 
36
37
  public
37
38
  def record(duration)
39
+ # TODO(sissel): histogram the duration
38
40
  @lock.synchronize do
39
41
  @invocations += 1
40
- # TODO(sissel): histogram the duration
42
+ @total_duration += duration
41
43
  end
42
44
  end # def record
43
45
 
@@ -53,6 +55,16 @@ class Cabin::Metrics::Timer
53
55
  return count
54
56
  end # def value
55
57
 
58
+ public
59
+ def to_hash
60
+ return @lock.synchronize do
61
+ {
62
+ :count => @invocations,
63
+ :duration_sum => @total_duration
64
+ }
65
+ end
66
+ end # def to_hash
67
+
56
68
  class TimerContext
57
69
  public
58
70
  def initialize(&stop_callback)
data/test/test_metrics.rb CHANGED
@@ -23,10 +23,12 @@ describe Cabin::Metrics do
23
23
  counter = @metrics.counter(self)
24
24
  0.upto(30) do |i|
25
25
  assert_equal(i, counter.value)
26
+ assert_equal({ :value => i }, counter.to_hash)
26
27
  counter.incr
27
28
  end
28
29
  31.downto(0) do |i|
29
30
  assert_equal(i, counter.value)
31
+ assert_equal({ :value => i }, counter.to_hash)
30
32
  counter.decr
31
33
  end
32
34
  end
@@ -35,6 +37,7 @@ describe Cabin::Metrics do
35
37
  meter = @metrics.meter(self)
36
38
  30.times do |i|
37
39
  assert_equal(i, meter.value)
40
+ assert_equal({ :value => i }, meter.to_hash)
38
41
  meter.mark
39
42
  end
40
43
  end
@@ -45,6 +48,7 @@ describe Cabin::Metrics do
45
48
  timer = @metrics.timer(self)
46
49
  30.times do |i|
47
50
  assert_equal(i, timer.count)
51
+ assert_equal(i, timer.to_hash[:count])
48
52
  timer.time { true }
49
53
  end
50
54
  end
metadata CHANGED
@@ -1,106 +1,86 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: cabin
3
- version: !ruby/object:Gem::Version
4
- hash: 19
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.1
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 3
9
- - 0
10
- version: 0.3.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Jordan Sissel
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-02-06 00:00:00 -08:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-02-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: json
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &20938580 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
33
22
  type: :runtime
34
- version_requirements: *id001
35
- description: This is an experiment to try and make logging more flexible and more consumable. Plain text logs are bullshit, let's emit structured and contextual logs. Metrics, too!
36
- email:
23
+ prerelease: false
24
+ version_requirements: *20938580
25
+ description: This is an experiment to try and make logging more flexible and more
26
+ consumable. Plain text logs are bullshit, let's emit structured and contextual logs.
27
+ Metrics, too!
28
+ email:
37
29
  - jls@semicomplete.com
38
- executables:
30
+ executables:
39
31
  - rubygems-cabin-test
40
32
  extensions: []
41
-
42
33
  extra_rdoc_files: []
43
-
44
- files:
45
- - lib/cabin/context.rb
46
- - lib/cabin/timer.rb
47
- - lib/cabin/outputs/stdlib-logger.rb
34
+ files:
35
+ - lib/cabin.rb
48
36
  - lib/cabin/outputs/em/stdlib-logger.rb
49
- - lib/cabin/mixins/logger.rb
50
- - lib/cabin/mixins/dragons.rb
51
- - lib/cabin/mixins/CAPSLOCK.rb
37
+ - lib/cabin/outputs/stdlib-logger.rb
38
+ - lib/cabin/channel.rb
52
39
  - lib/cabin/namespace.rb
53
- - lib/cabin/metrics/gauge.rb
40
+ - lib/cabin/metrics/counter.rb
54
41
  - lib/cabin/metrics/timer.rb
42
+ - lib/cabin/metrics/gauge.rb
55
43
  - lib/cabin/metrics/meter.rb
56
- - lib/cabin/metrics/counter.rb
44
+ - lib/cabin/timer.rb
57
45
  - lib/cabin/metrics.rb
58
- - lib/cabin/channel.rb
59
- - lib/cabin.rb
46
+ - lib/cabin/context.rb
47
+ - lib/cabin/mixins/dragons.rb
48
+ - lib/cabin/mixins/CAPSLOCK.rb
49
+ - lib/cabin/mixins/logger.rb
60
50
  - examples/fibonacci-timing.rb
61
51
  - examples/sinatra-logging.rb
62
52
  - examples/sample.rb
63
- - test/test_logging.rb
64
53
  - test/minitest-patch.rb
54
+ - test/test_logging.rb
65
55
  - test/test_metrics.rb
66
56
  - test/all.rb
67
57
  - LICENSE
68
58
  - CHANGELIST
69
59
  - bin/rubygems-cabin-test
70
- has_rdoc: true
71
60
  homepage: https://github.com/jordansissel/ruby-cabin
72
- licenses:
61
+ licenses:
73
62
  - Apache License (2.0)
74
63
  post_install_message:
75
64
  rdoc_options: []
76
-
77
- require_paths:
65
+ require_paths:
78
66
  - lib
79
67
  - lib
80
- required_ruby_version: !ruby/object:Gem::Requirement
68
+ required_ruby_version: !ruby/object:Gem::Requirement
81
69
  none: false
82
- requirements:
83
- - - ">="
84
- - !ruby/object:Gem::Version
85
- hash: 3
86
- segments:
87
- - 0
88
- version: "0"
89
- required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
75
  none: false
91
- requirements:
92
- - - ">="
93
- - !ruby/object:Gem::Version
94
- hash: 3
95
- segments:
96
- - 0
97
- version: "0"
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
98
80
  requirements: []
99
-
100
81
  rubyforge_project:
101
- rubygems_version: 1.6.2
82
+ rubygems_version: 1.8.10
102
83
  signing_key:
103
84
  specification_version: 3
104
85
  summary: Experiments in structured and contextual logging
105
86
  test_files: []
106
-