From f2c217ba9f8f30df045799d36498a8bfe1a5751c Mon Sep 17 00:00:00 2001 From: Justin Aiken <60tonangel@gmail.com> Date: Fri, 14 Feb 2014 16:28:43 -0700 Subject: [PATCH 1/2] =?UTF-8?q?Change=20to=20use=20a=20single=20socket,=20?= =?UTF-8?q?to=20avoid=20fd=20sockets=20leaking=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 3 +++ Gemfile | 2 ++ lib/adhearsion-stats.rb | 1 + lib/adhearsion-stats/plugin.rb | 5 +++-- lib/adhearsion-stats/stactor.rb | 19 +++++++++++++++++++ spec/adhearsion-stats/plugin_spec.rb | 7 ++++--- 6 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 lib/adhearsion-stats/stactor.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index a22316a..d75db05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# feature/single_socket + * Use a single UDP Socket + # 0.0.2 * BUGFIX: Log location relative to `Adhearsion.root` diff --git a/Gemfile b/Gemfile index b4e2a20..3a6ce6c 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ source "https://rubygems.org" +gem 'statsd-ruby', require: false, github: "JustinAiken/statsd", branch: "feature/optional_socket_argument" + gemspec diff --git a/lib/adhearsion-stats.rb b/lib/adhearsion-stats.rb index 4bd1c4f..82cc111 100644 --- a/lib/adhearsion-stats.rb +++ b/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" diff --git a/lib/adhearsion-stats/plugin.rb b/lib/adhearsion-stats/plugin.rb index 6829383..25cae1c 100644 --- a/lib/adhearsion-stats/plugin.rb +++ b/lib/adhearsion-stats/plugin.rb @@ -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 diff --git a/lib/adhearsion-stats/stactor.rb b/lib/adhearsion-stats/stactor.rb new file mode 100644 index 0000000..f829ff7 --- /dev/null +++ b/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 diff --git a/spec/adhearsion-stats/plugin_spec.rb b/spec/adhearsion-stats/plugin_spec.rb index f7225b8..d8d0893 100644 --- a/spec/adhearsion-stats/plugin_spec.rb +++ b/spec/adhearsion-stats/plugin_spec.rb @@ -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 From d625819a70ae7ded463dfc9ae5ed0ba83c443225 Mon Sep 17 00:00:00 2001 From: Justin Aiken <60tonangel@gmail.com> Date: Wed, 19 Feb 2014 14:51:53 -0700 Subject: [PATCH 2/2] Use my fork of the gem for now --- Gemfile | 2 -- adhearsion-stats.gemspec | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 3a6ce6c..b4e2a20 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,3 @@ source "https://rubygems.org" -gem 'statsd-ruby', require: false, github: "JustinAiken/statsd", branch: "feature/optional_socket_argument" - gemspec diff --git a/adhearsion-stats.gemspec b/adhearsion-stats.gemspec index 7ff624d..06682cf 100644 --- a/adhearsion-stats.gemspec +++ b/adhearsion-stats.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |s| s.require_paths = ["lib"] s.add_runtime_dependency %q, ["~> 2.1"] - s.add_runtime_dependency %q + s.add_runtime_dependency %q s.add_development_dependency %q, ['>= 0'] s.add_development_dependency %q, ["~> 1.0"]