Skip to content

Commit

Permalink
Make statsd notifier use nc again [References #42]
Browse files Browse the repository at this point in the history
  • Loading branch information
smith committed May 27, 2012
1 parent bb2194c commit ba2350d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ set :notifier_statsd_options, {
:port => "8125"
}
```

The `nc` ([Netcat](http://netcat.sourceforge.net/)) command is used to send messages to statsd and must be installed on the remote hosts. This is installed by default on most Unix machines.
8 changes: 2 additions & 6 deletions lib/capistrano/notifier/statsd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def self.load_into(configuration)
namespace :notify do
desc 'Notify StatsD of deploy.'
task :statsd do
Capistrano::Notifier::StatsD.new(configuration).perform
run Capistrano::Notifier::StatsD.new(configuration).perform
end
end
end
Expand All @@ -20,7 +20,7 @@ def self.load_into(configuration)
end

def perform
socket.send packet, 0, host, port
"echo #{packet.gsub('|', '\\|')} | nc -w 1 -u #{host} #{port}"
end

private
Expand Down Expand Up @@ -49,10 +49,6 @@ def port
options[:port]
end

def socket
@socket ||= UDPSocket.new
end

def with
case options[:with]
when :counter then "1|c"
Expand Down
9 changes: 3 additions & 6 deletions spec/capistrano/notifier/statsd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@
subject.send(:packet).should == "example.deploy:1|c"
end

it "sends a packet" do
UDPSocket.any_instance.should_receive(:send).once.with(
"example.deploy:1|c", 0, "127.0.0.1", "8125"
)

subject.perform
it "creates a command" do
subject.perform.should ==
"echo example.deploy:1\\|c | nc -w 1 -u 127.0.0.1 8125"
end

context "with a stage" do
Expand Down

0 comments on commit ba2350d

Please sign in to comment.