Skip to content

Commit

Permalink
Merge pull request #7 from JustinAiken/feature/single_socket
Browse files Browse the repository at this point in the history
Change to use a single socket, to avoid fd sockets leaking…
  • Loading branch information
JustinAiken committed Feb 19, 2014
2 parents 1f7f007 + d625819 commit 44e8568
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,6 @@
# feature/single_socket
* Use a single UDP Socket

# 0.0.2
* BUGFIX: Log location relative to `Adhearsion.root`

Expand Down
2 changes: 1 addition & 1 deletion adhearsion-stats.gemspec
Expand Up @@ -19,7 +19,7 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"]

s.add_runtime_dependency %q<adhearsion>, ["~> 2.1"]
s.add_runtime_dependency %q<statsd-ruby>
s.add_runtime_dependency %q<justinaiken-statsd>

s.add_development_dependency %q<coveralls>, ['>= 0']
s.add_development_dependency %q<bundler>, ["~> 1.0"]
Expand Down
1 change: 1 addition & 0 deletions lib/adhearsion-stats.rb
@@ -1,5 +1,6 @@
module AdhearsionStats; end

require "adhearsion-stats/version"
require "adhearsion-stats/stactor"
require "adhearsion-stats/metrics_logger"
require "adhearsion-stats/plugin"
5 changes: 3 additions & 2 deletions lib/adhearsion-stats/plugin.rb
Expand Up @@ -17,9 +17,10 @@ class Plugin < Adhearsion::Plugin
init :statsd do
AdhearsionStats.setup_logger if Adhearsion.config.statsd.log_metrics

AdhearsionStats.statsd = Statsd.new Adhearsion.config.statsd.host, Adhearsion.config.statsd.port
AdhearsionStats.loaded = true
statsd = Statsd.new Adhearsion.config.statsd.host, Adhearsion.config.statsd.port, UDPSocket.new
AdhearsionStats.statsd = AdhearsionStats::Stactor.new statsd

AdhearsionStats.loaded = true
logger.info "Adhearsion-Stats has been loaded"
end
end
Expand Down
19 changes: 19 additions & 0 deletions lib/adhearsion-stats/stactor.rb
@@ -0,0 +1,19 @@
module AdhearsionStats
class Stactor
include Celluloid

attr_accessor :statsd

def initialize(statsd)
@statsd = statsd
end

def send_stat(meth, *args, &blk)
statsd.send meth, *args, &blk
end

def method_missing(meth, *args, &blk)
self.async.send_stat meth, *args, &blk
end
end
end
7 changes: 4 additions & 3 deletions spec/adhearsion-stats/plugin_spec.rb
Expand Up @@ -22,9 +22,10 @@
end

it "sets init variables" do
subject.statsd.should be_an_instance_of Statsd
subject.statsd.host.should == "127.0.0.1"
subject.statsd.port.should == 8125
subject.statsd.should be_an_instance_of AdhearsionStats::Stactor
subject.statsd.statsd.should be_an_instance_of Statsd
subject.statsd.statsd.host.should == "127.0.0.1"
subject.statsd.statsd.port.should == 8125

subject.metrics_logger.should be_an_instance_of AdhearsionStats::MetricsLogger
subject.loaded.should be_true
Expand Down

0 comments on commit 44e8568

Please sign in to comment.