fozzie 0.0.12 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/fozzie/classes.rb +16 -11
- data/lib/fozzie/configuration.rb +23 -3
- data/lib/fozzie/version.rb +1 -1
- data/spec/lib/fozzie/configuration_spec.rb +44 -0
- data/spec/lib/fozzie_spec.rb +3 -7
- metadata +22 -22
data/lib/fozzie/classes.rb
CHANGED
@@ -4,11 +4,14 @@ module Fozzie
|
|
4
4
|
module Classes
|
5
5
|
|
6
6
|
class AbstractFozzie < Statsd
|
7
|
-
attr_reader :prefix
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
attr_reader :prefix, :configuration
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@namespace = Fozzie.c.data_prefix
|
12
|
+
super Fozzie.c.host, Fozzie.c.port
|
13
|
+
|
14
|
+
self
|
12
15
|
end
|
13
16
|
|
14
17
|
def time_to_do(stat, sample_rate=1, &block); time_for(stat, sample_rate, &block); end
|
@@ -48,21 +51,23 @@ module Fozzie
|
|
48
51
|
|
49
52
|
def send_to_socket(message)
|
50
53
|
begin
|
51
|
-
|
52
|
-
|
54
|
+
ip = Fozzie.c.ip_from_host
|
55
|
+
raise RuntimeError, "Could not locate IP" unless ip
|
56
|
+
|
57
|
+
self.class.logger.debug {"Statsd: #{message}"} if self.class.logger
|
58
|
+
socket.send(message, 0, ip, Fozzie.c.port)
|
59
|
+
rescue SocketError, RuntimeError => exc
|
60
|
+
self.class.logger.debug {"Statsd Failure: #{exc.message}"} if self.class.logger
|
53
61
|
nil
|
54
62
|
end
|
55
63
|
end
|
56
64
|
|
57
65
|
end
|
58
66
|
|
59
|
-
NAMESPACES = %w{Stats S Statistics Warehouse}
|
60
|
-
|
61
67
|
def self.included(klass)
|
62
|
-
|
63
|
-
NAMESPACES.each do |klas|
|
68
|
+
Fozzie.c.namespaces.each do |klas|
|
64
69
|
# set a constant
|
65
|
-
Kernel.const_set(klas, AbstractFozzie.new
|
70
|
+
Kernel.const_set(klas, AbstractFozzie.new) unless const_defined?(klas)
|
66
71
|
end
|
67
72
|
end
|
68
73
|
|
data/lib/fozzie/configuration.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'core_ext/hash'
|
2
|
+
require 'resolv'
|
2
3
|
|
3
4
|
module Fozzie
|
4
5
|
|
@@ -6,7 +7,7 @@ module Fozzie
|
|
6
7
|
# that will be used within the Fozzie codebase.
|
7
8
|
class Configuration
|
8
9
|
|
9
|
-
attr_accessor :env, :config_path, :host, :port, :appname
|
10
|
+
attr_accessor :env, :config_path, :host, :port, :appname, :namespaces
|
10
11
|
|
11
12
|
def initialize(args = {})
|
12
13
|
merge_and_assign_config(args)
|
@@ -15,10 +16,18 @@ module Fozzie
|
|
15
16
|
end
|
16
17
|
|
17
18
|
def data_prefix
|
18
|
-
s = [appname, env].collect {|s| s.empty? ? nil : s }.compact.join('.').strip
|
19
|
+
s = [appname, origin_name, env].collect {|s| s.empty? ? nil : s.gsub('.', '-') }.compact.join('.').strip
|
19
20
|
(s.empty? ? nil : s)
|
20
21
|
end
|
21
22
|
|
23
|
+
def ip_from_host
|
24
|
+
@ip_from_host ||= host_to_ip
|
25
|
+
end
|
26
|
+
|
27
|
+
def origin_name
|
28
|
+
@origin_name ||= %x{uname -n}.strip
|
29
|
+
end
|
30
|
+
|
22
31
|
private
|
23
32
|
|
24
33
|
# Handle the merging of the given configuaration, and the default config.
|
@@ -40,10 +49,21 @@ module Fozzie
|
|
40
49
|
:port => 8125,
|
41
50
|
:config_path => '',
|
42
51
|
:env => (ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development'),
|
43
|
-
:appname => ''
|
52
|
+
:appname => '',
|
53
|
+
:namespaces => %w{Stats S Statistics Warehouse}
|
44
54
|
}.dup
|
45
55
|
end
|
46
56
|
|
57
|
+
def host_to_ip
|
58
|
+
return self.host unless self.host.match(ip_address_regex).nil?
|
59
|
+
ips = Resolv.getaddresses(self.host)
|
60
|
+
ips.compact.reject {|ip| ip.to_s.match(ip_address_regex).nil? }.first unless ips.nil?
|
61
|
+
end
|
62
|
+
|
63
|
+
def ip_address_regex
|
64
|
+
/^(?:\d{1,3}\.){3}\d{1,3}$/
|
65
|
+
end
|
66
|
+
|
47
67
|
def full_config_path(path)
|
48
68
|
File.expand_path('config/fozzie.yml', path)
|
49
69
|
end
|
data/lib/fozzie/version.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'resolv'
|
2
3
|
|
3
4
|
describe Fozzie::Configuration do
|
4
5
|
|
@@ -12,6 +13,7 @@ describe Fozzie::Configuration do
|
|
12
13
|
|
13
14
|
it "attempts to load configuration from yaml" do
|
14
15
|
c = Fozzie::Configuration.new({:env => 'test', :config_path => 'spec/'})
|
16
|
+
c.stubs(:origin_name).returns("")
|
15
17
|
c.host.should == '1.1.1.1'
|
16
18
|
c.port.should == 9876
|
17
19
|
c.appname.should == 'fozzie'
|
@@ -23,16 +25,58 @@ describe Fozzie::Configuration do
|
|
23
25
|
end
|
24
26
|
|
25
27
|
it "creates a data prefix" do
|
28
|
+
subject.stubs(:origin_name).returns("")
|
26
29
|
subject.data_prefix.should == 'development'
|
27
30
|
end
|
28
31
|
|
29
32
|
it "creates a data prefix with appname when set" do
|
33
|
+
subject.stubs(:origin_name).returns("")
|
30
34
|
subject.appname = 'astoria'
|
31
35
|
subject.data_prefix.should == 'astoria.development'
|
32
36
|
end
|
33
37
|
|
38
|
+
it "creates a prefix with origin" do
|
39
|
+
subject.stubs(:origin_name).returns("app.server.local")
|
40
|
+
subject.appname = 'astoria'
|
41
|
+
subject.data_prefix.should == 'astoria.app-server-local.development'
|
42
|
+
end
|
43
|
+
|
34
44
|
it "handles missing configuration namespace" do
|
35
45
|
proc { Fozzie::Configuration.new({:env => 'blbala', :config_path => 'spec/'}) }.should_not raise_error
|
36
46
|
end
|
37
47
|
|
48
|
+
it "#namespaces" do
|
49
|
+
subject.namespaces.should be_kind_of(Array)
|
50
|
+
subject.namespaces.should include("Stats")
|
51
|
+
subject.namespaces.should include("S")
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#ip_from_host" do
|
55
|
+
|
56
|
+
it "returns host if host an ip" do
|
57
|
+
c = Fozzie::Configuration.new({:env => 'test', :config_path => nil, :host => '127.0.0.1'})
|
58
|
+
c.ip_from_host.should == '127.0.0.1'
|
59
|
+
end
|
60
|
+
|
61
|
+
it "assigns nil on miss" do
|
62
|
+
Resolv.expects(:getaddresses).with('some.awesome.log.server').returns([]).twice
|
63
|
+
|
64
|
+
c = Fozzie::Configuration.new({:env => 'test', :config_path => nil, :host => 'some.awesome.log.server'})
|
65
|
+
c.ip_from_host.should == nil
|
66
|
+
c.ip_from_host.should == nil
|
67
|
+
end
|
68
|
+
|
69
|
+
it "looks up ip from host" do
|
70
|
+
c = Fozzie::Configuration.new({:env => 'test', :config_path => nil, :host => 'lonelyplanet.com'})
|
71
|
+
c.ip_from_host.should match(/^(?:\d{1,3}\.){3}\d{1,3}$/)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "caches the ip once it is retrieved" do
|
75
|
+
Resolv.expects(:getaddresses).with('lonelyplanet.com').returns(["1.1.1.1"])
|
76
|
+
c = Fozzie::Configuration.new({:env => 'test', :config_path => nil, :host => 'lonelyplanet.com'})
|
77
|
+
c.ip_from_host.should == c.ip_from_host
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
38
82
|
end
|
data/spec/lib/fozzie_spec.rb
CHANGED
@@ -12,13 +12,13 @@ describe Fozzie do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it "creates new classes for statistics gathering" do
|
15
|
-
Fozzie
|
15
|
+
Fozzie.c.namespaces.each do |k|
|
16
16
|
Kernel.const_defined?(k).should == true
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
it "acts like its inherited parent" do
|
21
|
-
Fozzie
|
21
|
+
Fozzie.c.namespaces.each do |k|
|
22
22
|
kl = Kernel.const_get(k)
|
23
23
|
kl.should respond_to(:increment)
|
24
24
|
kl.should respond_to(:decrement)
|
@@ -29,16 +29,12 @@ describe Fozzie do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it "acts an a singleton" do
|
32
|
-
Fozzie
|
32
|
+
Fozzie.c.namespaces.each do |k|
|
33
33
|
kl1, kl2 = Kernel.const_get(k), Kernel.const_get(k)
|
34
34
|
kl1.should == kl2
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
it "assigns namespace when passed" do
|
39
|
-
Fozzie::AbstractFozzie.new(1,2, 'a').namespace.should == 'a'
|
40
|
-
end
|
41
|
-
|
42
38
|
it "times a given block" do
|
43
39
|
Stats.expects(:timing).with() {|b, val, timing| b == 'data.bin' && (1000..1200).include?(val) }.twice
|
44
40
|
Stats.time_for('data.bin') { sleep 1 }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fozzie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: statsd-ruby
|
16
|
-
requirement: &
|
16
|
+
requirement: &70101336334120 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70101336334120
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &70101336333380 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70101336333380
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70101336332560 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70101336332560
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: mocha
|
49
|
-
requirement: &
|
49
|
+
requirement: &70101336331840 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70101336331840
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: syntax
|
60
|
-
requirement: &
|
60
|
+
requirement: &70101336496260 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70101336496260
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rack-test
|
71
|
-
requirement: &
|
71
|
+
requirement: &70101336495340 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70101336495340
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: simplecov
|
82
|
-
requirement: &
|
82
|
+
requirement: &70101336494540 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70101336494540
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: sinatra
|
93
|
-
requirement: &
|
93
|
+
requirement: &70101336493560 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70101336493560
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: actionpack
|
104
|
-
requirement: &
|
104
|
+
requirement: &70101336492460 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70101336492460
|
113
113
|
description: Gem allows statistics gathering from Ruby and Ruby on Rails applications
|
114
114
|
to Statsd
|
115
115
|
email:
|
@@ -156,7 +156,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
156
156
|
version: '0'
|
157
157
|
segments:
|
158
158
|
- 0
|
159
|
-
hash:
|
159
|
+
hash: 2372667692060957828
|
160
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
161
|
none: false
|
162
162
|
requirements:
|
@@ -165,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
165
|
version: '0'
|
166
166
|
segments:
|
167
167
|
- 0
|
168
|
-
hash:
|
168
|
+
hash: 2372667692060957828
|
169
169
|
requirements: []
|
170
170
|
rubyforge_project: fozzie
|
171
171
|
rubygems_version: 1.8.10
|