counters 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/counters/stats_d.rb +14 -2
- data/lib/counters/version.rb +1 -1
- data/spec/statsd_counter_spec.rb +14 -0
- metadata +2 -2
data/lib/counters/stats_d.rb
CHANGED
@@ -1,13 +1,25 @@
|
|
1
1
|
require "socket"
|
2
|
+
require "uri"
|
2
3
|
|
3
4
|
module Counters
|
4
5
|
class StatsD < Counters::Base
|
5
6
|
attr_reader :host, :port, :socket
|
6
7
|
|
7
|
-
def initialize(
|
8
|
+
def initialize(*args)
|
9
|
+
options = args.last.is_a?(Hash) ? args.pop : Hash.new
|
8
10
|
super(options)
|
9
11
|
|
10
|
-
|
12
|
+
url = case args.length
|
13
|
+
when 0
|
14
|
+
options.fetch(:url) { raise ArgumentError, "Missing :url key from #{args.first}" }
|
15
|
+
when 2
|
16
|
+
"statsd://#{args.first}:#{args.last}"
|
17
|
+
else
|
18
|
+
raise ArgumentError, "Expected either a Hash or a host and port arguments, found: #{args.inspect}"
|
19
|
+
end
|
20
|
+
|
21
|
+
uri = URI.parse(url)
|
22
|
+
@host, @port = uri.host, uri.port
|
11
23
|
@socket = options.fetch(:socket) { UDPSocket.new }
|
12
24
|
end
|
13
25
|
|
data/lib/counters/version.rb
CHANGED
data/spec/statsd_counter_spec.rb
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
+
describe Counters::StatsD, "#initialize" do
|
4
|
+
it "should accept a Hash with a :url key" do
|
5
|
+
counter = Counters::StatsD.new(:url => "statsd://statsd.internal:9991")
|
6
|
+
counter.host.should == "statsd.internal"
|
7
|
+
counter.port.should == 9991
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should accept a host/port pair" do
|
11
|
+
counter = Counters::StatsD.new("127.0.0.1", 8125)
|
12
|
+
counter.host.should == "127.0.0.1"
|
13
|
+
counter.port.should == 8125
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
3
17
|
describe Counters::StatsD do
|
4
18
|
let :socket do
|
5
19
|
double("socket")
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: counters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.1.
|
5
|
+
version: 1.1.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- "Fran\xC3\xA7ois Beausoleil"
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-04-07 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|