Class: Krane::StatsD

Inherits:
Object
  • Object
show all
Defined in:
lib/krane/statsd.rb

Defined Under Namespace

Modules: MeasureMethods

Constant Summary collapse

PREFIX =
"Krane"

Class Method Summary collapse

Class Method Details

.clientObject


13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/krane/statsd.rb', line 13

def self.client
  @client ||= begin
    sink = if ::StatsD::Instrument::Environment.current.env.fetch('STATSD_ENV', nil) == 'development'
      ::StatsD::Instrument::LogSink.new(Logger.new($stderr))
    elsif (addr = ::StatsD::Instrument::Environment.current.env.fetch('STATSD_ADDR', nil))
      ::StatsD::Instrument::UDPSink.for_addr(addr)
    else
      ::StatsD::Instrument::NullSink.new
    end
    ::StatsD::Instrument::Client.new(prefix: PREFIX, sink: sink, default_sample_rate: 1.0)
  end
end

.duration(start_time) ⇒ Object


9
10
11
# File 'lib/krane/statsd.rb', line 9

def self.duration(start_time)
  (Time.now.utc - start_time).round(1)
end