Class: Percy::Stats
- Inherits:
-
Datadog::Statsd
- Object
- Datadog::Statsd
- Percy::Stats
- Defined in:
- lib/percy/stats.rb
Constant Summary collapse
- DEFAULT_HOST =
ENV.fetch( 'DATADOG_AGENT_HOST', ::Datadog::Statsd::Connection::DEFAULT_HOST, )
- DEFAULT_PORT =
Integer( ENV.fetch( 'DATADOG_AGENT_PORT', ::Datadog::Statsd::Connection::DEFAULT_PORT, ), )
- DEFAULT_TAGS =
%W[ env:#{ENV.fetch('PERCY_ENV', 'development')} ].freeze
Instance Method Summary collapse
-
#initialize(host = DEFAULT_HOST, port = DEFAULT_PORT, tags: DEFAULT_TAGS, **kwargs) ⇒ Stats
constructor
A new instance of Stats.
-
#start_timing ⇒ Object
Equivalent to stats.time, but without wrapping in blocks and dealing with var scoping issues.
- #stop_timing(stat, options = {}) ⇒ Object
- #time_since(stat, start, opts = {}) ⇒ Object
-
#time_since_monotonic(stat, start, opts = {}) ⇒ Object
dogstatsd uses a monotonic (linearly increasing) clock to calculate time intervals, so this should be used where necessary.
Constructor Details
#initialize(host = DEFAULT_HOST, port = DEFAULT_PORT, tags: DEFAULT_TAGS, **kwargs) ⇒ Stats
Returns a new instance of Stats.
22 23 24 25 26 27 28 29 |
# File 'lib/percy/stats.rb', line 22 def initialize( host = DEFAULT_HOST, port = DEFAULT_PORT, tags: DEFAULT_TAGS, **kwargs ) super(host, port, tags: , **kwargs) end |
Instance Method Details
#start_timing ⇒ Object
Equivalent to stats.time, but without wrapping in blocks and dealing with var scoping issues.
38 39 40 41 |
# File 'lib/percy/stats.rb', line 38 def start_timing @_timing_start = now true end |
#stop_timing(stat, options = {}) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/percy/stats.rb', line 43 def stop_timing(stat, = {}) # Programmer mistake, so raise an error. raise 'no timing started' unless @_timing_start time_since_monotonic(stat, @_timing_start, ) @_timing_start = nil true end |
#time_since(stat, start, opts = {}) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/percy/stats.rb', line 64 def time_since(stat, start, opts = {}) unless start.instance_of? Time raise ArgumentError, 'start value must be Time' end timing(stat, ((Time.now.to_f - start.to_f) * 1000).round, opts) end |
#time_since_monotonic(stat, start, opts = {}) ⇒ Object
dogstatsd uses a monotonic (linearly increasing) clock to calculate time intervals, so this should be used where necessary. However, it’s not possible to compare monotonic time values with fixed times, so both are available.
56 57 58 59 60 61 62 |
# File 'lib/percy/stats.rb', line 56 def time_since_monotonic(stat, start, opts = {}) unless start.instance_of? Float raise ArgumentError, 'start value must be Float' end timing(stat, ((now.to_f - start.to_f) * 1000).round, opts) end |