Class: Watchman
- Inherits:
-
Object
- Object
- Watchman
- Defined in:
- lib/watchman.rb,
lib/watchman/version.rb,
lib/watchman/mock_statsd.rb
Defined Under Namespace
Classes: MockStatsd, SubmitTypeError
Constant Summary collapse
- VERSION =
"0.8.0"
Class Attribute Summary collapse
-
.host ⇒ Object
Returns the value of attribute host.
-
.port ⇒ Object
Returns the value of attribute port.
-
.prefix ⇒ Object
Returns the value of attribute prefix.
-
.test_mode ⇒ Object
Returns the value of attribute test_mode.
Class Method Summary collapse
- .benchmark(name, args = {}) ⇒ Object
- .decrement(name, args = {}) ⇒ Object
- .increment(name, args = {}) ⇒ Object
- .submit(name, value, args = {}) ⇒ Object
Class Attribute Details
.host ⇒ Object
Returns the value of attribute host.
11 12 13 |
# File 'lib/watchman.rb', line 11 def host @host end |
.port ⇒ Object
Returns the value of attribute port.
12 13 14 |
# File 'lib/watchman.rb', line 12 def port @port end |
.prefix ⇒ Object
Returns the value of attribute prefix.
10 11 12 |
# File 'lib/watchman.rb', line 10 def prefix @prefix end |
.test_mode ⇒ Object
Returns the value of attribute test_mode.
13 14 15 |
# File 'lib/watchman.rb', line 13 def test_mode @test_mode end |
Class Method Details
.benchmark(name, args = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/watchman.rb', line 29 def benchmark(name, args = {}) = args[:tags] || [] result = nil time = Benchmark.measure do result = yield end submit(name, (time.real * 1000).floor, type: :timing, tags: ) result end |
.decrement(name, args = {}) ⇒ Object
49 50 51 52 53 |
# File 'lib/watchman.rb', line 49 def decrement(name, args = {}) = args[:tags] || [] submit(name, -1, type: :count, tags: ) end |
.increment(name, args = {}) ⇒ Object
43 44 45 46 47 |
# File 'lib/watchman.rb', line 43 def increment(name, args = {}) = args[:tags] || [] submit(name, 1, type: :count, tags: ) end |
.submit(name, value, args = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/watchman.rb', line 15 def submit(name, value, args = {}) type = args[:type] || :gauge = args[:tags] || [] metric = metric_name_with_prefix(name, ) case type when :gauge then statsd_client.gauge(metric, value) when :timing then statsd_client.timing(metric, value) when :count then statsd_client.count(metric, value) else raise SubmitTypeError.new("Submit type '#{type}' is not recognized") end end |