Class: Takwimu::Reporter
- Inherits:
-
Object
- Object
- Takwimu::Reporter
- Defined in:
- lib/takwimu/reporter.rb
Overview
The reporter is used to send stats to the server.
Example:
statsd = Statsd.new('127.0.0.1', "8125")
reporter = Reporter.new(statsd: , sample_rate: 10)
reporter.report_statsd('barnes.counters' => {"hello" => 2})
Instance Attribute Summary collapse
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#sample_rate ⇒ Object
Returns the value of attribute sample_rate.
-
#statsd ⇒ Object
Returns the value of attribute statsd.
Instance Method Summary collapse
-
#initialize(statsd:, sample_rate:, hostname:) ⇒ Reporter
constructor
A new instance of Reporter.
- #report(env) ⇒ Object
- #report_statsd(env) ⇒ Object
Constructor Details
#initialize(statsd:, sample_rate:, hostname:) ⇒ Reporter
Returns a new instance of Reporter.
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/takwimu/reporter.rb', line 35 def initialize(statsd: , sample_rate:, hostname:) @statsd = statsd @sample_rate = sample_rate.to_f @hostname = hostname if @statsd.respond_to?(:easy) @statsd_method = statsd.method(:easy) else @statsd_method = statsd.method(:batch) end end |
Instance Attribute Details
#hostname ⇒ Object
Returns the value of attribute hostname.
33 34 35 |
# File 'lib/takwimu/reporter.rb', line 33 def hostname @hostname end |
#sample_rate ⇒ Object
Returns the value of attribute sample_rate.
33 34 35 |
# File 'lib/takwimu/reporter.rb', line 33 def sample_rate @sample_rate end |
#statsd ⇒ Object
Returns the value of attribute statsd.
33 34 35 |
# File 'lib/takwimu/reporter.rb', line 33 def statsd @statsd end |
Instance Method Details
#report(env) ⇒ Object
47 48 49 |
# File 'lib/takwimu/reporter.rb', line 47 def report(env) report_statsd env if @statsd end |
#report_statsd(env) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/takwimu/reporter.rb', line 51 def report_statsd(env) @statsd_method.call do |statsd| env[Takwimu::COUNTERS].each do |metric, value| statsd.count(:"#{hostname}.#{metric}", value, @sample_rate) end # for :gauge, use sample rate of 1, since gauges in statsd have no sampling characteristics. env[Takwimu::GAUGES].each do |metric, value| statsd.gauge(:"#{hostname}.#{metric}", value, 1.0) end env[Takwimu::TIMERS].each do |metric, value| statsd.timing(:"#{hostname}.#{metric}", value, 1.0) end end end |