metriks 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +7 -0
- data/LICENSE +21 -0
- data/README.md +333 -0
- data/Rakefile +150 -0
- data/lib/metriks.rb +27 -0
- data/lib/metriks/counter.rb +44 -0
- data/lib/metriks/ewma.rb +63 -0
- data/lib/metriks/histogram.rb +103 -0
- data/lib/metriks/meter.rb +73 -0
- data/lib/metriks/registry.rb +174 -0
- data/lib/metriks/reporter/logger.rb +94 -0
- data/lib/metriks/reporter/proc_title.rb +59 -0
- data/lib/metriks/simple_moving_average.rb +60 -0
- data/lib/metriks/timer.rb +93 -0
- data/lib/metriks/uniform_sample.rb +35 -0
- data/lib/metriks/utilization_timer.rb +43 -0
- data/metriks.gemspec +90 -0
- data/test/counter_test.rb +21 -0
- data/test/histogram_test.rb +38 -0
- data/test/logger_reporter_test.rb +30 -0
- data/test/meter_test.rb +28 -0
- data/test/metriks_test.rb +27 -0
- data/test/proc_title_reporter_test.rb +25 -0
- data/test/registry_test.rb +37 -0
- data/test/test_helper.rb +8 -0
- data/test/timer_test.rb +29 -0
- data/test/utilization_timer_test.rb +25 -0
- metadata +135 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
require 'metriks/counter'
|
4
|
+
|
5
|
+
class CounterTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@counter = Metriks::Counter.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_increment
|
11
|
+
@counter.increment
|
12
|
+
|
13
|
+
assert_equal 1, @counter.count
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_increment_by_more
|
17
|
+
@counter.increment 10
|
18
|
+
|
19
|
+
assert_equal 10, @counter.count
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
require 'metriks/histogram'
|
4
|
+
|
5
|
+
class HistogramTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@histogram = Metriks::Histogram.new(Metriks::UniformSample.new(Metriks::Histogram::DEFAULT_SAMPLE_SIZE))
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_min
|
11
|
+
@histogram.update(5)
|
12
|
+
@histogram.update(10)
|
13
|
+
|
14
|
+
assert_equal 5, @histogram.min
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_max
|
18
|
+
@histogram.update(5)
|
19
|
+
@histogram.update(10)
|
20
|
+
|
21
|
+
assert_equal 10, @histogram.max
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_mean
|
25
|
+
@histogram.update(5)
|
26
|
+
@histogram.update(10)
|
27
|
+
|
28
|
+
assert_equal 7, @histogram.mean
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_2000
|
32
|
+
2000.times do |idx|
|
33
|
+
@histogram.update(idx)
|
34
|
+
end
|
35
|
+
|
36
|
+
assert_equal 1999, @histogram.max
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
require 'logger'
|
4
|
+
require 'metriks/reporter/logger'
|
5
|
+
|
6
|
+
class LoggerReporterTest < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
@stringio = StringIO.new
|
9
|
+
@logger = ::Logger.new(@stringio)
|
10
|
+
@registry = Metriks::Registry.new
|
11
|
+
|
12
|
+
@reporter = Metriks::Reporter::Logger.new(:registry => @registry, :logger => @logger)
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
@reporter.stop
|
17
|
+
@registry.stop
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_write
|
21
|
+
@registry.meter('meter.testing').mark
|
22
|
+
@registry.counter('counter.testing').increment
|
23
|
+
@registry.timer('timer.testing').update(1.5)
|
24
|
+
@registry.utilization_timer('utilization_timer.testing').update(1.5)
|
25
|
+
|
26
|
+
@reporter.write
|
27
|
+
|
28
|
+
assert_match /time=\d/, @stringio.string
|
29
|
+
end
|
30
|
+
end
|
data/test/meter_test.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
require 'metriks/meter'
|
4
|
+
|
5
|
+
class MeterTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@meter = Metriks::Meter.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
@meter.stop
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_meter
|
15
|
+
@meter.mark
|
16
|
+
|
17
|
+
assert_equal 1, @meter.count
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_one_minute_rate
|
21
|
+
@meter.mark 1000
|
22
|
+
|
23
|
+
# Pretend it's been 5 seconds
|
24
|
+
@meter.tick
|
25
|
+
|
26
|
+
assert_equal 200, @meter.one_minute_rate
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class MetriksTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
Metriks::Registry.default.clear
|
6
|
+
end
|
7
|
+
|
8
|
+
def teardown
|
9
|
+
Metriks::Registry.default.clear
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_counter
|
13
|
+
assert_not_nil Metriks.counter('testing')
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_meter
|
17
|
+
assert_not_nil Metriks.meter('testing')
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_timer
|
21
|
+
assert_not_nil Metriks.timer('testing')
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_utilization_timer
|
25
|
+
assert_not_nil Metriks.utilization_timer('testing')
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
require 'metriks/reporter/proc_title'
|
4
|
+
|
5
|
+
class ProcTitleReporterTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@reporter = Metriks::Reporter::ProcTitle.new
|
8
|
+
@original_proctitle = $0.dup
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
@reporter.stop
|
13
|
+
$0 = @original_proctitle
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_generate_title
|
17
|
+
@reporter.add 'test', 'sec' do
|
18
|
+
50.333
|
19
|
+
end
|
20
|
+
|
21
|
+
title = @reporter.send(:generate_title)
|
22
|
+
|
23
|
+
assert_equal 'test: 50.3/sec', title
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
require 'metriks/registry'
|
4
|
+
|
5
|
+
class RegistryTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@registry = Metriks::Registry.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
@registry.stop
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_counter
|
15
|
+
assert_not_nil @registry.counter('testing')
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_meter
|
19
|
+
assert_not_nil @registry.meter('testing')
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_timer
|
23
|
+
assert_not_nil @registry.timer('testing')
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_utilization_timer
|
27
|
+
assert_not_nil @registry.utilization_timer('testing')
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_calling_counter_twice
|
31
|
+
assert_not_nil @registry.counter('testing')
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_default
|
35
|
+
assert_not_nil Metriks::Registry.default
|
36
|
+
end
|
37
|
+
end
|
data/test/test_helper.rb
ADDED
data/test/timer_test.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
require 'metriks/timer'
|
4
|
+
|
5
|
+
class TimerTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@timer = Metriks::Timer.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
@timer.stop
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_timer
|
15
|
+
@timer.time do
|
16
|
+
sleep 0.1
|
17
|
+
end
|
18
|
+
|
19
|
+
assert_in_delta 0.1, @timer.mean, 0.01
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_timer_without_block
|
23
|
+
t = @timer.time
|
24
|
+
sleep 0.1
|
25
|
+
t.stop
|
26
|
+
|
27
|
+
assert_in_delta 0.1, @timer.mean, 0.01
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
require 'metriks/utilization_timer'
|
4
|
+
|
5
|
+
class UtilizationTimerTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@timer = Metriks::UtilizationTimer.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
@timer.stop
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_timer
|
15
|
+
5.times do
|
16
|
+
@timer.update(0.10)
|
17
|
+
@timer.update(0.15)
|
18
|
+
end
|
19
|
+
|
20
|
+
@timer.instance_variable_get(:@meter).tick
|
21
|
+
@timer.instance_variable_get(:@duration_meter).tick
|
22
|
+
|
23
|
+
assert_in_delta 0.25, @timer.one_minute_utilization, 0.1
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: metriks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 8
|
8
|
+
- 1
|
9
|
+
version: 0.8.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Eric Lindvall
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2012-02-27 00:00:00 -08:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: atomic
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 0
|
30
|
+
version: "1.0"
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: hitimes
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
segments:
|
41
|
+
- 1
|
42
|
+
- 1
|
43
|
+
version: "1.1"
|
44
|
+
type: :runtime
|
45
|
+
version_requirements: *id002
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: tomdoc
|
48
|
+
prerelease: false
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
segments:
|
54
|
+
- 0
|
55
|
+
- 2
|
56
|
+
version: "0.2"
|
57
|
+
type: :development
|
58
|
+
version_requirements: *id003
|
59
|
+
description: An experimental metrics client.
|
60
|
+
email: eric@sevenscale.com
|
61
|
+
executables: []
|
62
|
+
|
63
|
+
extensions: []
|
64
|
+
|
65
|
+
extra_rdoc_files:
|
66
|
+
- README.md
|
67
|
+
- LICENSE
|
68
|
+
files:
|
69
|
+
- Gemfile
|
70
|
+
- LICENSE
|
71
|
+
- README.md
|
72
|
+
- Rakefile
|
73
|
+
- lib/metriks.rb
|
74
|
+
- lib/metriks/counter.rb
|
75
|
+
- lib/metriks/ewma.rb
|
76
|
+
- lib/metriks/histogram.rb
|
77
|
+
- lib/metriks/meter.rb
|
78
|
+
- lib/metriks/registry.rb
|
79
|
+
- lib/metriks/reporter/logger.rb
|
80
|
+
- lib/metriks/reporter/proc_title.rb
|
81
|
+
- lib/metriks/simple_moving_average.rb
|
82
|
+
- lib/metriks/timer.rb
|
83
|
+
- lib/metriks/uniform_sample.rb
|
84
|
+
- lib/metriks/utilization_timer.rb
|
85
|
+
- metriks.gemspec
|
86
|
+
- test/counter_test.rb
|
87
|
+
- test/histogram_test.rb
|
88
|
+
- test/logger_reporter_test.rb
|
89
|
+
- test/meter_test.rb
|
90
|
+
- test/metriks_test.rb
|
91
|
+
- test/proc_title_reporter_test.rb
|
92
|
+
- test/registry_test.rb
|
93
|
+
- test/test_helper.rb
|
94
|
+
- test/timer_test.rb
|
95
|
+
- test/utilization_timer_test.rb
|
96
|
+
has_rdoc: true
|
97
|
+
homepage: https://github.com/eric/metriks_client
|
98
|
+
licenses: []
|
99
|
+
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options:
|
102
|
+
- --charset=UTF-8
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
segments:
|
110
|
+
- 0
|
111
|
+
version: "0"
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
version: "0"
|
119
|
+
requirements: []
|
120
|
+
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 1.3.6
|
123
|
+
signing_key:
|
124
|
+
specification_version: 2
|
125
|
+
summary: An experimental metrics client
|
126
|
+
test_files:
|
127
|
+
- test/counter_test.rb
|
128
|
+
- test/histogram_test.rb
|
129
|
+
- test/logger_reporter_test.rb
|
130
|
+
- test/meter_test.rb
|
131
|
+
- test/metriks_test.rb
|
132
|
+
- test/proc_title_reporter_test.rb
|
133
|
+
- test/registry_test.rb
|
134
|
+
- test/timer_test.rb
|
135
|
+
- test/utilization_timer_test.rb
|