Permalink
Browse files

Expose statsd host and port. Default host to 127.0.0.1

  • Loading branch information...
1 parent 372be30 commit 86a4bfe80260314b81ed1c214d0326344087f08d @jeremy committed Dec 4, 2011
Showing with 21 additions and 5 deletions.
  1. +7 −1 lib/statsd.rb
  2. +14 −4 spec/statsd_spec.rb
View
@@ -16,6 +16,12 @@ class Statsd
# A namespace to prepend to all statsd calls.
attr_reader :namespace
+ # StatsD host. Defaults to 127.0.0.1.
+ attr_accessor :host
+
+ # StatsD port. Defaults to 8125.
+ attr_accessor :port
+
class << self
# Set to a standard logger instance to enable debug logging.
attr_reader :logger
@@ -30,7 +36,7 @@ def logger=(logger) #:nodoc:
# @param [String] host your statsd host
# @param [Integer] port your statsd port
- def initialize(host, port=8125)
+ def initialize(host='127.0.0.1', port=8125)
@host, @port = host, port
@prefix = nil
@socket = UDPSocket.new
View
@@ -2,8 +2,7 @@
describe Statsd do
class Statsd
- # we need to test these
- attr_reader :host, :port
+ # we need to stub this
attr_accessor :socket
end
@@ -20,8 +19,19 @@ class Statsd
@statsd.port.must_equal 1234
end
- it "should default the port to 8125" do
- Statsd.new('localhost').instance_variable_get('@port').must_equal 8125
+ it "should default the host to 127.0.0.1 and port to 8125" do
+ statsd = Statsd.new
+ statsd.host.must_equal '127.0.0.1'
+ statsd.port.must_equal 8125
+ end
+ end
+
+ describe "#host and #port" do
+ it "should set host and port" do
+ @statsd.host = '1.2.3.4'
+ @statsd.port = 5678
+ @statsd.host.must_equal '1.2.3.4'
+ @statsd.port.must_equal 5678
end
end

0 comments on commit 86a4bfe

Please sign in to comment.