fozzie 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/README.md +6 -0
- data/Rakefile +1 -0
- data/fozzie.gemspec +28 -0
- data/lib/core_ext/hash.rb +16 -0
- data/lib/fozzie.rb +8 -0
- data/lib/fozzie/classes.rb +42 -0
- data/lib/fozzie/config.rb +19 -0
- data/lib/fozzie/configuration.rb +60 -0
- data/lib/fozzie/version.rb +3 -0
- data/spec/config/fozzie.yml +5 -0
- data/spec/lib/core_ext/hash_spec.rb +33 -0
- data/spec/lib/fozzie/config_spec.rb +24 -0
- data/spec/lib/fozzie/configuration_spec.rb +34 -0
- data/spec/lib/fozzie/version_spec.rb +10 -0
- data/spec/lib/fozzie_spec.rb +46 -0
- data/spec/spec_helper.rb +16 -0
- metadata +144 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use --create 1.9.3@fozzie
|
data/Gemfile
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/fozzie.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "fozzie/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "fozzie"
|
7
|
+
s.version = Fozzie::VERSION
|
8
|
+
s.authors = ["Marc Watts"]
|
9
|
+
s.email = ["marcw.watts@loneplanet.com"]
|
10
|
+
s.summary = %q{Statistics gem for LonelyPlanet Online}
|
11
|
+
s.description = %q{Gem allows statistics gathering from Ruby and Ruby
|
12
|
+
on Rails applications within LonelyPlanet Online}
|
13
|
+
|
14
|
+
s.rubyforge_project = "fozzie"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency 'statsd'
|
22
|
+
s.add_dependency 'bson_ext'
|
23
|
+
|
24
|
+
s.add_development_dependency 'rake'
|
25
|
+
s.add_development_dependency "rspec"
|
26
|
+
s.add_development_dependency "mocha"
|
27
|
+
s.add_development_dependency "simplecov"
|
28
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Hash
|
2
|
+
|
3
|
+
# Return self as symbolized keys hash
|
4
|
+
def symbolize_keys
|
5
|
+
self.dup.inject({}) do |hsh, (k,v)|
|
6
|
+
hsh[k.to_sym] = (v.respond_to?(:symbolize_keys) ? v.symbolize_keys : v)
|
7
|
+
hsh
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# Replace self with symbolized keys hash
|
12
|
+
def symbolize_keys!
|
13
|
+
self.replace(self.symbolize_keys)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
data/lib/fozzie.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'statsd'
|
2
|
+
|
3
|
+
module Fozzie
|
4
|
+
module Classes
|
5
|
+
|
6
|
+
class AbstractFozzie < Statsd::Client
|
7
|
+
attr_reader :prefix
|
8
|
+
|
9
|
+
def initialize(host, port, prefix = nil)
|
10
|
+
@prefix = prefix
|
11
|
+
super host, port
|
12
|
+
end
|
13
|
+
|
14
|
+
def time_for(data, &block)
|
15
|
+
tick = Time.now.usec
|
16
|
+
block.call
|
17
|
+
tock = Time.now.usec
|
18
|
+
timing(data, (tock - tick))
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
# Overload the send_stats method to automicatially prefix the data bucket string
|
24
|
+
def send_stats(data, sample_rate = 1)
|
25
|
+
super "#{@prefix}#{data}", sample_rate
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
NAMESPACES = %w{Stats S}
|
31
|
+
|
32
|
+
def self.included(klass)
|
33
|
+
host, port, prefix = Fozzie.c.host, Fozzie.c.port, Fozzie.c.data_prefix
|
34
|
+
NAMESPACES.each do |klas|
|
35
|
+
# set a constant
|
36
|
+
Kernel.const_set(klas, AbstractFozzie.new(host, port, prefix)) unless const_defined?(klas)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'core_ext/hash'
|
2
|
+
|
3
|
+
module Fozzie
|
4
|
+
|
5
|
+
# Fozzie configuration allows assignment of global properties
|
6
|
+
# that will be used within the Fozzie codebase.
|
7
|
+
class Configuration
|
8
|
+
|
9
|
+
attr_accessor :env, :config_path, :host, :port, :appname
|
10
|
+
|
11
|
+
def initialize(args = {})
|
12
|
+
merge_and_assign_config(args)
|
13
|
+
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def data_prefix
|
18
|
+
s = "%s." % env
|
19
|
+
s = appname << ".#{s}" unless appname.nil? || appname.empty?
|
20
|
+
s
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
# Handle the merging of the given configuaration, and the default config.
|
26
|
+
# @return [Hash]
|
27
|
+
def merge_and_assign_config(args = {})
|
28
|
+
arg = self.class.default_configuration.merge(args.symbolize_keys)
|
29
|
+
arg.delete_if {|key, val| !self.respond_to?(key.to_sym) }
|
30
|
+
arg.merge!(config_from_yaml(arg))
|
31
|
+
arg.each {|a,v| self.send("#{a}=", v) }
|
32
|
+
|
33
|
+
arg
|
34
|
+
end
|
35
|
+
|
36
|
+
# Default configuration settings
|
37
|
+
# @return [Hash]
|
38
|
+
def self.default_configuration
|
39
|
+
{
|
40
|
+
:host => '127.0.0.1',
|
41
|
+
:port => 8125,
|
42
|
+
:config_path => '',
|
43
|
+
:env => (ENV['RAILS_ENV'] || 'development'),
|
44
|
+
:appname => ''
|
45
|
+
}.dup
|
46
|
+
end
|
47
|
+
|
48
|
+
def full_config_path(path)
|
49
|
+
File.expand_path('config/fozzie.yml', path)
|
50
|
+
end
|
51
|
+
|
52
|
+
def config_from_yaml(args)
|
53
|
+
fp = full_config_path(args[:config_path])
|
54
|
+
return {} unless File.exists?(fp)
|
55
|
+
YAML.load(File.open(fp))[args[:env]].symbolize_keys
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'core_ext/hash'
|
3
|
+
|
4
|
+
describe Hash do
|
5
|
+
|
6
|
+
it { should respond_to(:symbolize_keys) }
|
7
|
+
it { should respond_to(:symbolize_keys!) }
|
8
|
+
|
9
|
+
it "manipulates keys correctly" do
|
10
|
+
{
|
11
|
+
'1' => 1,
|
12
|
+
'2' => 2,
|
13
|
+
'3' => 3
|
14
|
+
}.symbolize_keys.should == {
|
15
|
+
:"1" => 1,
|
16
|
+
:"2" => 2,
|
17
|
+
:"3" => 3
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns copy when bang not provided" do
|
22
|
+
hsh = { '1' => 1, '2' => 2, '3' => 3 }
|
23
|
+
hsh.symbolize_keys
|
24
|
+
hsh.should == { '1' => 1, '2' => 2, '3' => 3 }
|
25
|
+
end
|
26
|
+
|
27
|
+
it "replaces self when bang provided" do
|
28
|
+
hsh = { '1' => 1, '2' => 2, '3' => 3 }
|
29
|
+
hsh.symbolize_keys!
|
30
|
+
hsh.should == { :"1" => 1, :"2" => 2, :"3" => 3 }
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Fozzie::Config do
|
4
|
+
|
5
|
+
subject do
|
6
|
+
F = Class.new { extend Fozzie::Config } unless defined?(F)
|
7
|
+
F
|
8
|
+
end
|
9
|
+
|
10
|
+
it { should respond_to(:configure) }
|
11
|
+
it { should respond_to(:config) }
|
12
|
+
it { should respond_to(:c) }
|
13
|
+
|
14
|
+
it "allows dynamic assignment" do
|
15
|
+
{
|
16
|
+
:host => 'somewhere.local',
|
17
|
+
:port => 99
|
18
|
+
}.each do |field, val|
|
19
|
+
F.configure {|c| c.send("#{field}=", val) }
|
20
|
+
F.c.send(field).should == val
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Fozzie::Configuration do
|
4
|
+
|
5
|
+
it "#host" do
|
6
|
+
subject.host.should be_kind_of(String)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "#port" do
|
10
|
+
subject.port.should be_kind_of(Fixnum)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "attempts to load configuration from yaml" do
|
14
|
+
c = Fozzie::Configuration.new({:env => 'test', :config_path => 'spec/'})
|
15
|
+
c.host.should == '1.1.1.1'
|
16
|
+
c.port.should == 9876
|
17
|
+
c.appname.should == 'fozzie'
|
18
|
+
c.data_prefix.should == 'fozzie.test.'
|
19
|
+
end
|
20
|
+
|
21
|
+
it "defaults env" do
|
22
|
+
subject.env.should == 'development'
|
23
|
+
end
|
24
|
+
|
25
|
+
it "creates a data prefix" do
|
26
|
+
subject.data_prefix.should == 'development.'
|
27
|
+
end
|
28
|
+
|
29
|
+
it "creates a data prefix with appname when set" do
|
30
|
+
subject.appname = 'astoria'
|
31
|
+
subject.data_prefix.should == 'astoria.development.'
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fozzie/classes'
|
3
|
+
|
4
|
+
describe Fozzie do
|
5
|
+
|
6
|
+
it { should respond_to(:c) }
|
7
|
+
it { should respond_to(:config) }
|
8
|
+
|
9
|
+
it "has configuration" do
|
10
|
+
Fozzie.config.should be_kind_of(Fozzie::Configuration)
|
11
|
+
Fozzie.c.should be_kind_of(Fozzie::Configuration)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "creates new classes for statistics gathering" do
|
15
|
+
Fozzie::Classes::NAMESPACES.each do |k|
|
16
|
+
Kernel.const_defined?(k).should == true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "acts like its inherited parent" do
|
21
|
+
Fozzie::Classes::NAMESPACES.each do |k|
|
22
|
+
kl = Kernel.const_get(k)
|
23
|
+
kl.should respond_to(:increment)
|
24
|
+
kl.should respond_to(:decrement)
|
25
|
+
kl.should respond_to(:timing)
|
26
|
+
kl.should respond_to(:update_counter)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "acts an a singleton" do
|
31
|
+
Fozzie::Classes::NAMESPACES.each do |k|
|
32
|
+
kl1, kl2 = Kernel.const_get(k), Kernel.const_get(k)
|
33
|
+
kl1.should == kl2
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "assigns prefix when passed" do
|
38
|
+
Fozzie::AbstractFozzie.new(1,2, 'a').prefix.should == 'a'
|
39
|
+
end
|
40
|
+
|
41
|
+
it "times a given block" do
|
42
|
+
Stats.expects(:timing).with() {|b, val| b == 'data.bin' && (100..1200).include?(val) }
|
43
|
+
Stats.time_for('data.bin') { sleep 1 }
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
root = File.expand_path('../', File.dirname(__FILE__))
|
2
|
+
lib = File.expand_path('lib', root)
|
3
|
+
$:.unshift(root, lib)
|
4
|
+
|
5
|
+
require 'simplecov'
|
6
|
+
SimpleCov.start
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.mock_with :mocha
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'fozzie'
|
13
|
+
Fozzie.configure do |config|
|
14
|
+
config.host = '127.0.0.1'
|
15
|
+
config.port = 8809
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fozzie
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Marc Watts
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-12-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: statsd
|
16
|
+
requirement: &70178457746280 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70178457746280
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: bson_ext
|
27
|
+
requirement: &70178457745620 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70178457745620
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rake
|
38
|
+
requirement: &70178457720320 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70178457720320
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: &70178457719780 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70178457719780
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: mocha
|
60
|
+
requirement: &70178457719300 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70178457719300
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: &70178457718620 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70178457718620
|
80
|
+
description: ! "Gem allows statistics gathering from Ruby and Ruby \n on Rails
|
81
|
+
applications within LonelyPlanet Online"
|
82
|
+
email:
|
83
|
+
- marcw.watts@loneplanet.com
|
84
|
+
executables: []
|
85
|
+
extensions: []
|
86
|
+
extra_rdoc_files: []
|
87
|
+
files:
|
88
|
+
- .gitignore
|
89
|
+
- .rvmrc
|
90
|
+
- Gemfile
|
91
|
+
- README.md
|
92
|
+
- Rakefile
|
93
|
+
- fozzie.gemspec
|
94
|
+
- lib/core_ext/hash.rb
|
95
|
+
- lib/fozzie.rb
|
96
|
+
- lib/fozzie/classes.rb
|
97
|
+
- lib/fozzie/config.rb
|
98
|
+
- lib/fozzie/configuration.rb
|
99
|
+
- lib/fozzie/version.rb
|
100
|
+
- spec/config/fozzie.yml
|
101
|
+
- spec/lib/core_ext/hash_spec.rb
|
102
|
+
- spec/lib/fozzie/config_spec.rb
|
103
|
+
- spec/lib/fozzie/configuration_spec.rb
|
104
|
+
- spec/lib/fozzie/version_spec.rb
|
105
|
+
- spec/lib/fozzie_spec.rb
|
106
|
+
- spec/spec_helper.rb
|
107
|
+
homepage:
|
108
|
+
licenses: []
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
segments:
|
120
|
+
- 0
|
121
|
+
hash: -2960279826758926432
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
none: false
|
124
|
+
requirements:
|
125
|
+
- - ! '>='
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
segments:
|
129
|
+
- 0
|
130
|
+
hash: -2960279826758926432
|
131
|
+
requirements: []
|
132
|
+
rubyforge_project: fozzie
|
133
|
+
rubygems_version: 1.8.10
|
134
|
+
signing_key:
|
135
|
+
specification_version: 3
|
136
|
+
summary: Statistics gem for LonelyPlanet Online
|
137
|
+
test_files:
|
138
|
+
- spec/config/fozzie.yml
|
139
|
+
- spec/lib/core_ext/hash_spec.rb
|
140
|
+
- spec/lib/fozzie/config_spec.rb
|
141
|
+
- spec/lib/fozzie/configuration_spec.rb
|
142
|
+
- spec/lib/fozzie/version_spec.rb
|
143
|
+
- spec/lib/fozzie_spec.rb
|
144
|
+
- spec/spec_helper.rb
|