spectator-rb 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rubocop.yml +12 -0
- data/.travis.yml +6 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +46 -0
- data/LICENSE +202 -0
- data/OSSMETADATA +1 -0
- data/README.md +110 -0
- data/Rakefile +13 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/buildViaTravis.sh +7 -0
- data/lib/spectator.rb +22 -0
- data/lib/spectator/atomic_number.rb +49 -0
- data/lib/spectator/clock.rb +57 -0
- data/lib/spectator/counter.rb +34 -0
- data/lib/spectator/distribution_summary.rb +53 -0
- data/lib/spectator/gauge.rb +34 -0
- data/lib/spectator/http.rb +30 -0
- data/lib/spectator/measure.rb +24 -0
- data/lib/spectator/meter_id.rb +52 -0
- data/lib/spectator/registry.rb +298 -0
- data/lib/spectator/timer.rb +64 -0
- data/lib/spectator/version.rb +3 -0
- data/spectator.gemspec +30 -0
- metadata +126 -0
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spectator/atomic_number'
|
2
|
+
require 'spectator/clock'
|
3
|
+
|
4
|
+
module Spectator
|
5
|
+
# The class Timer is intended to track a large number of
|
6
|
+
# short running events. Example would be something like
|
7
|
+
# an http request. Though "short running" is a bit subjective
|
8
|
+
# the assumption is that it should be under a minute.
|
9
|
+
class Timer
|
10
|
+
def initialize(id, clock = SystemClock.new)
|
11
|
+
@id = id
|
12
|
+
@clock = clock
|
13
|
+
|
14
|
+
@count = AtomicNumber.new(0)
|
15
|
+
@total_time = AtomicNumber.new(0)
|
16
|
+
@total_sq = AtomicNumber.new(0)
|
17
|
+
@max = AtomicNumber.new(Float::NAN)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Update the statistics kept by this timer. If the amount of nanoseconds
|
21
|
+
# passed is negative, the value will be ignored.
|
22
|
+
def record(nanos)
|
23
|
+
return if nanos < 0
|
24
|
+
@count.add_and_get(1)
|
25
|
+
@total_time.add_and_get(nanos)
|
26
|
+
@total_sq.add_and_get(nanos * nanos)
|
27
|
+
@max.max(nanos)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Record the time it takes to execute the given block
|
31
|
+
#
|
32
|
+
def time
|
33
|
+
start = @clock.monotonic_time
|
34
|
+
yield
|
35
|
+
elapsed = @clock.monotonic_time - start
|
36
|
+
record(elapsed)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Get the number of events recorded
|
40
|
+
def count
|
41
|
+
@count.get
|
42
|
+
end
|
43
|
+
|
44
|
+
# Get the total time of events recorded in nanoseconds
|
45
|
+
def total_time
|
46
|
+
@total_time.get
|
47
|
+
end
|
48
|
+
|
49
|
+
# Measure this timer. It returns the count, totalTime in seconds,
|
50
|
+
# max in seconds, and totalOfSquares (normalized) to seconds to seconds
|
51
|
+
def measure
|
52
|
+
total_seconds = @total_time.get_and_set(0) / 1e9
|
53
|
+
max_seconds = @max.get_and_set(Float::NAN) / 1e9
|
54
|
+
tot_sq_seconds = @total_sq.get_and_set(0) / 1e18
|
55
|
+
|
56
|
+
cnt = Measure.new(@id.with_stat('count'), @count.get_and_set(0))
|
57
|
+
tot = Measure.new(@id.with_stat('totalTime'), total_seconds)
|
58
|
+
tot_sq = Measure.new(@id.with_stat('totalOfSquares'), tot_sq_seconds)
|
59
|
+
mx = Measure.new(@id.with_stat('max'), max_seconds)
|
60
|
+
|
61
|
+
[cnt, tot, tot_sq, mx]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/spectator.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('lib', __dir__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'spectator/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'spectator-rb'
|
8
|
+
spec.version = Spectator::VERSION
|
9
|
+
spec.authors = ['Daniel Muino']
|
10
|
+
spec.email = ['dmuino@netflix.com']
|
11
|
+
spec.licenses = ['Apache-2.0']
|
12
|
+
|
13
|
+
spec.summary = 'Simple library for instrumenting code to record ' \
|
14
|
+
'dimensional time series.'
|
15
|
+
spec.description = 'Library for instrumenting ruby applications, ' \
|
16
|
+
'sending metrics to an Atlas aggregator service.'
|
17
|
+
spec.homepage = 'https://github.com/Netflix/spectator-rb'
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
f.match(%r{^(test|spec|features)/})
|
21
|
+
end
|
22
|
+
spec.bindir = 'exe'
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ['lib']
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
27
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
spec.add_development_dependency 'rubocop', '~> 0.55'
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spectator-rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Muino
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.55'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.55'
|
69
|
+
description: Library for instrumenting ruby applications, sending metrics to an Atlas
|
70
|
+
aggregator service.
|
71
|
+
email:
|
72
|
+
- dmuino@netflix.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rubocop.yml"
|
79
|
+
- ".travis.yml"
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.lock
|
82
|
+
- LICENSE
|
83
|
+
- OSSMETADATA
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- bin/console
|
87
|
+
- bin/setup
|
88
|
+
- buildViaTravis.sh
|
89
|
+
- lib/spectator.rb
|
90
|
+
- lib/spectator/atomic_number.rb
|
91
|
+
- lib/spectator/clock.rb
|
92
|
+
- lib/spectator/counter.rb
|
93
|
+
- lib/spectator/distribution_summary.rb
|
94
|
+
- lib/spectator/gauge.rb
|
95
|
+
- lib/spectator/http.rb
|
96
|
+
- lib/spectator/measure.rb
|
97
|
+
- lib/spectator/meter_id.rb
|
98
|
+
- lib/spectator/registry.rb
|
99
|
+
- lib/spectator/timer.rb
|
100
|
+
- lib/spectator/version.rb
|
101
|
+
- spectator.gemspec
|
102
|
+
homepage: https://github.com/Netflix/spectator-rb
|
103
|
+
licenses:
|
104
|
+
- Apache-2.0
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.5.2
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Simple library for instrumenting code to record dimensional time series.
|
126
|
+
test_files: []
|