class Takwimu::Reporter
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})
Attributes
hostname[RW]
sample_rate[RW]
statsd[RW]
Public Class Methods
new(statsd: , sample_rate:, hostname:)
click to toggle source
# 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
Public Instance Methods
report(env)
click to toggle source
# File lib/takwimu/reporter.rb, line 47 def report(env) report_statsd env if @statsd end
report_statsd(env)
click to toggle source
# 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