Module: Watchman
Constant Summary collapse
- VERSION =
"0.3.0"
Instance 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.
Instance Method Summary collapse
- #benchmark(name) ⇒ Object
- #metric_name_with_prefix(name) ⇒ Object
- #statsd_client ⇒ Object
- #submit(name, value) ⇒ Object
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
9 10 11 |
# File 'lib/watchman.rb', line 9 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
10 11 12 |
# File 'lib/watchman.rb', line 10 def port @port end |
#prefix ⇒ Object
Returns the value of attribute prefix.
8 9 10 |
# File 'lib/watchman.rb', line 8 def prefix @prefix end |
Instance Method Details
#benchmark(name) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/watchman.rb', line 20 def benchmark(name) result = nil time = Benchmark.measure do result = yield end statsd_client.timing(metric_name_with_prefix(name), (time.real * 1000).floor) result end |
#metric_name_with_prefix(name) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/watchman.rb', line 32 def metric_name_with_prefix(name) if @prefix "#{@prefix}.#{name}" else name end end |
#statsd_client ⇒ Object
12 13 14 |
# File 'lib/watchman.rb', line 12 def statsd_client @client ||= Statsd.new(@host, @port) end |
#submit(name, value) ⇒ Object
16 17 18 |
# File 'lib/watchman.rb', line 16 def submit(name, value) statsd_client.gauge(metric_name_with_prefix(name), value) end |