rackamole 0.1.1 → 0.2.0
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/HISTORY +6 -1
- data/README.rdoc +14 -0
- data/lib/rackamole/mole.rb +17 -3
- data/lib/rackamole/store/mongo_db.rb +23 -6
- data/lib/rackamole.rb +1 -1
- data/samples/sinatra/moled.rb +7 -5
- data/spec/rackamole/mole_spec.rb +38 -0
- data/spec/test_configs/rackamole_test.yml +42 -0
- metadata +3 -2
data/HISTORY
CHANGED
@@ -5,4 +5,9 @@
|
|
5
5
|
* Updated mongo store strategy
|
6
6
|
* Tossed out mongo mapper. Trying to stay closer to the metal
|
7
7
|
* Shortened col names for saving space. Unfortunately lame but necessary
|
8
|
-
* Moved user info into separate collection.
|
8
|
+
* Moved user info into separate collection.
|
9
|
+
|
10
|
+
0.2.0
|
11
|
+
* YAML options - You can now load the rack component from a yaml file. This is
|
12
|
+
very handy in framework where Rackamole options varies depending on the environment.
|
13
|
+
Please refer to spec/test_configs/rackamole_test.yml for an example
|
data/README.rdoc
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
== RackAMole
|
2
|
+
|
2
3
|
Observe your web applications in the wild!
|
3
4
|
|
4
5
|
== DESCRIPTION:
|
@@ -37,6 +38,9 @@ interactions and leverage these findings for the next iteration of your applicat
|
|
37
38
|
* Logging
|
38
39
|
* Hitimes
|
39
40
|
* MongoDb + mongo ruby adapter
|
41
|
+
* Twitter4r
|
42
|
+
* Chronic
|
43
|
+
* Actionmailer
|
40
44
|
|
41
45
|
== INSTALL:
|
42
46
|
|
@@ -77,6 +81,12 @@ interactions and leverage these findings for the next iteration of your applicat
|
|
77
81
|
This assumes that you have session enabled to identify a user if not the mole will log the user
|
78
82
|
as 'Unknown'
|
79
83
|
|
84
|
+
=== Notables
|
85
|
+
|
86
|
+
Rackamole also comes with an option to specify a yaml config file to initialize the various settings.
|
87
|
+
This comes in very handy when you need to specify different options depending on the environment you
|
88
|
+
are operating in. Please see the spec/test_configs/rackamole_test.yml for an example.
|
89
|
+
|
80
90
|
=== Storing moled information
|
81
91
|
|
82
92
|
Rackamole currently comes with a single storage strategy. More will come in the near future, but
|
@@ -93,6 +103,10 @@ interactions and leverage these findings for the next iteration of your applicat
|
|
93
103
|
This expect a local mongo instance to be running on the default port. You can change the
|
94
104
|
location by adding :host and :port options.
|
95
105
|
|
106
|
+
NOTE: If you intend to use Wackamole please use the following mongo database naming convention
|
107
|
+
|
108
|
+
mole_{app_name}_{environment}_mdb
|
109
|
+
|
96
110
|
== LICENSE:
|
97
111
|
|
98
112
|
(The MIT License)
|
data/lib/rackamole/mole.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'hitimes'
|
2
2
|
require 'json'
|
3
3
|
require 'mongo'
|
4
|
+
require 'yaml'
|
4
5
|
|
5
|
-
# BOZO !! - Need args validator or use dsl as the args are out of control...
|
6
6
|
module Rack
|
7
7
|
class Mole
|
8
8
|
|
@@ -16,6 +16,11 @@ module Rack
|
|
16
16
|
#
|
17
17
|
# === Options
|
18
18
|
#
|
19
|
+
# :config_file :: This option will load rackamole options from a file versus individual options.
|
20
|
+
# You can leverage yaml and erb with the current rackamole context to specify each of
|
21
|
+
# the following options but within a yaml file. This gives more flexibility to customize
|
22
|
+
# the rack component for specific environment. You can specify the :environment option or
|
23
|
+
# the default will be development.
|
19
24
|
# :app_name :: The name of the application (Default: Moled App)
|
20
25
|
# :log_level :: Rackamole logger level. (Default: info )
|
21
26
|
# :environment :: The environment for the application ie :environment => RAILS_ENV
|
@@ -92,7 +97,16 @@ module Rack
|
|
92
97
|
|
93
98
|
# Load up configuration options
|
94
99
|
def init_options( opts )
|
95
|
-
|
100
|
+
if opts[:config_file] && (env = opts[:environment] || "development")
|
101
|
+
raise "Unable to find rackamole config file #{opts[:config_file]}" unless ::File.exists?( opts[:config_file] )
|
102
|
+
begin
|
103
|
+
opts = YAML.load( ERB.new( IO.read( opts[:config_file] ) ).result( binding ) )[env]
|
104
|
+
opts[:environment] = env
|
105
|
+
rescue => boom
|
106
|
+
raise "Unable to parse Rackamole config file #{boom}"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
@options = default_options.merge( opts )
|
96
110
|
end
|
97
111
|
|
98
112
|
# Mole default options
|
@@ -102,7 +116,7 @@ module Rack
|
|
102
116
|
:log_level => :info,
|
103
117
|
:expiration => 60*60, # 1 hour
|
104
118
|
:app_name => "Moled App",
|
105
|
-
:environment => '
|
119
|
+
:environment => 'development',
|
106
120
|
:excluded_paths => [/.?\.ico/, /.?\.png/],
|
107
121
|
:perf_threshold => 10.0,
|
108
122
|
:store => Rackamole::Store::Log.new
|
@@ -7,7 +7,7 @@ module Rackamole
|
|
7
7
|
# Mongo adapter. Stores mole info to a mongo database.
|
8
8
|
class MongoDb
|
9
9
|
|
10
|
-
attr_reader :database, :logs, :features, :users #:nodoc:
|
10
|
+
attr_reader :host, :port, :db_name, :database, :logs, :features, :users #:nodoc:
|
11
11
|
|
12
12
|
# Initializes the mongo db store. MongoDb can be used as a persitent store for
|
13
13
|
# mole information. This is a preferred store for the mole as it will allow you
|
@@ -29,6 +29,16 @@ module Rackamole
|
|
29
29
|
init_mongo( opts )
|
30
30
|
end
|
31
31
|
|
32
|
+
def to_yaml( opts={} )
|
33
|
+
YAML::quick_emit( object_id, opts ) do |out|
|
34
|
+
out.map( taguri, to_yaml_style ) do |map|
|
35
|
+
map.add( :host , host )
|
36
|
+
map.add( :port , port )
|
37
|
+
map.add( :db_name , db_name )
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
32
42
|
# Dump mole info to a mongo database. There are actually 2 collections
|
33
43
|
# for mole information. Namely features and logs. The features collection hold
|
34
44
|
# application and feature information and is referenced in the mole log. The logs
|
@@ -37,6 +47,10 @@ module Rackamole
|
|
37
47
|
def mole( arguments )
|
38
48
|
return if arguments.empty?
|
39
49
|
|
50
|
+
unless @connection
|
51
|
+
init_mongo( :host => host, :port => port, :db_name => db_name )
|
52
|
+
end
|
53
|
+
|
40
54
|
# get a dup of the args since will mock with the original
|
41
55
|
args = arguments.clone
|
42
56
|
|
@@ -58,8 +72,13 @@ module Rackamole
|
|
58
72
|
end
|
59
73
|
|
60
74
|
def init_mongo( opts )
|
61
|
-
@
|
62
|
-
@
|
75
|
+
@host = opts[:host]
|
76
|
+
@port = opts[:port]
|
77
|
+
@db_name = opts[:db_name]
|
78
|
+
|
79
|
+
@connection = Mongo::Connection.new( @host, @port, :logger => opts[:logger] )
|
80
|
+
@database = @connection.db( @db_name )
|
81
|
+
|
63
82
|
@features = database.collection( 'features' )
|
64
83
|
@logs = database.collection( 'logs' )
|
65
84
|
@users = database.collection( 'users' )
|
@@ -80,7 +99,7 @@ module Rackamole
|
|
80
99
|
{
|
81
100
|
:host => 'localhost',
|
82
101
|
:port => Mongo::Connection::DEFAULT_PORT,
|
83
|
-
:
|
102
|
+
:db_name => 'mole_mdb'
|
84
103
|
}
|
85
104
|
end
|
86
105
|
|
@@ -133,8 +152,6 @@ module Rackamole
|
|
133
152
|
# NOTE : Using min key to reduce storage needs. I know not that great for higher level api's :-(
|
134
153
|
# also saving date and time as ints. same deal...
|
135
154
|
def save_log( user_id, feature_id, args )
|
136
|
-
puts "Saving LOG for #{feature_id} -- #{user_id}"
|
137
|
-
puts caller.inspect
|
138
155
|
now = args.delete( :created_at )
|
139
156
|
row = {
|
140
157
|
min_field( :type ) => args[:type],
|
data/lib/rackamole.rb
CHANGED
data/samples/sinatra/moled.rb
CHANGED
@@ -11,16 +11,18 @@ puts "mole_sinatra_#{Sinatra::Application.environment}_mdb"
|
|
11
11
|
use Rack::Lint
|
12
12
|
use Rack::Session::Cookie
|
13
13
|
use Rack::Mole, {
|
14
|
-
:app_name => "
|
14
|
+
:app_name => "Franky",
|
15
15
|
:environment => Sinatra::Application.environment,
|
16
16
|
:log_level => :debug,
|
17
17
|
:user_key => :user_name,
|
18
|
-
|
19
|
-
|
18
|
+
:store => Rackamole::Store::MongoDb.new(
|
19
|
+
:host => 'ec2-174-129-88-130.compute-1.amazonaws.com',
|
20
|
+
:database => "mole_franky_#{Sinatra::Application.environment}_mdb" ),
|
21
|
+
# :store => Rackamole::Store::MongoDb.new( :database => "mole_franky_#{Sinatra::Application.environment}_mdb" ),
|
20
22
|
:expiration => 10,
|
21
23
|
:perf_threshold => 0.2,
|
22
|
-
:twitter => { :username => 'moled', :password => 'fernand~1', :alert_on => [Rackamole.perf, Rackamole.fault] },
|
23
|
-
:excluded_paths => [ /.+?\.css/, /.+?\.js/, /.+?\.png/ ]
|
24
|
+
# :twitter => { :username => 'moled', :password => 'fernand~1', :alert_on => [Rackamole.perf, Rackamole.fault] },
|
25
|
+
:excluded_paths => [ /.+?\.css/, /.+?\.js/, /.+?\.png/, /.+?\.ico/ ]
|
24
26
|
}
|
25
27
|
end
|
26
28
|
|
data/spec/rackamole/mole_spec.rb
CHANGED
@@ -365,4 +365,42 @@ describe Rack::Mole do
|
|
365
365
|
@rack.send( :id_browser, 'IBrowse' ).should == 'N/A'
|
366
366
|
end
|
367
367
|
end
|
368
|
+
|
369
|
+
# ---------------------------------------------------------------------------
|
370
|
+
describe 'YAML load' do
|
371
|
+
before :all do
|
372
|
+
@config_file = File.join( File.dirname(__FILE__), %w[.. test_configs rackamole_test.yml] )
|
373
|
+
end
|
374
|
+
|
375
|
+
it "should load the test env correctly from a yaml file" do
|
376
|
+
@rack = Rack::Mole.new( nil, :environment => 'test', :config_file => @config_file )
|
377
|
+
@rack.send( 'options' )[:moleable].should == false
|
378
|
+
end
|
379
|
+
|
380
|
+
it "should load the dev env correctly from a yaml file" do
|
381
|
+
@rack = Rack::Mole.new( nil, :environment => 'development', :config_file => @config_file )
|
382
|
+
opts = @rack.send( 'options' )
|
383
|
+
opts[:moleable].should == true
|
384
|
+
opts[:app_name].should == 'TestApp'
|
385
|
+
opts[:user_key].should == :user_name
|
386
|
+
opts[:perf_threshold].should == 2
|
387
|
+
|
388
|
+
@rack.send( :alertable?, :twitter, Rackamole.perf ).should == true
|
389
|
+
@rack.send( :alertable?, :twitter, Rackamole.fault ).should == false
|
390
|
+
@rack.send( :alertable?, :email, Rackamole.fault ).should == true
|
391
|
+
@rack.send( :alertable?, :email, Rackamole.perf ).should == false
|
392
|
+
end
|
393
|
+
|
394
|
+
it "should load the prod env correctly" do
|
395
|
+
@rack = Rack::Mole.new( nil, :environment => 'production', :config_file => @config_file )
|
396
|
+
opts = @rack.send( 'options' )
|
397
|
+
opts[:moleable].should == true
|
398
|
+
opts[:app_name].should == 'TestApp'
|
399
|
+
opts[:perf_threshold].should == 5
|
400
|
+
(opts[:store].instance_of?(Rackamole::Store::MongoDb)).should == true
|
401
|
+
opts[:store].db_name.should == "mole_fred_production"
|
402
|
+
opts[:store].port.should == 10
|
403
|
+
opts[:store].host.should == "fred"
|
404
|
+
end
|
405
|
+
end
|
368
406
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
# Rackamole Test rack configuration file
|
3
|
+
# -----------------------------------------------------------------------------
|
4
|
+
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
# Shared configuration
|
7
|
+
defaults: &defaults
|
8
|
+
:moleable: true
|
9
|
+
:app_name: TestApp
|
10
|
+
:user_key: :user_name
|
11
|
+
:twitter:
|
12
|
+
:username: bumblebtuna
|
13
|
+
:password: secret
|
14
|
+
:alert_on:
|
15
|
+
- <%= Rackamole.perf %>
|
16
|
+
:email:
|
17
|
+
:from: Bozo@acme.com
|
18
|
+
:to:
|
19
|
+
- 'fernand@acme.com'
|
20
|
+
:alert_on:
|
21
|
+
- <%= Rackamole.fault %>
|
22
|
+
|
23
|
+
# -----------------------------------------------------------------------------
|
24
|
+
#
|
25
|
+
development:
|
26
|
+
<<: *defaults
|
27
|
+
:perf_threshold: 2
|
28
|
+
|
29
|
+
# -----------------------------------------------------------------------------
|
30
|
+
# Turn mole off in test
|
31
|
+
test:
|
32
|
+
:moleable: false
|
33
|
+
|
34
|
+
# -----------------------------------------------------------------------------
|
35
|
+
# Use mongo based store in production env
|
36
|
+
production:
|
37
|
+
<<: *defaults
|
38
|
+
:perf_threshold: 5
|
39
|
+
:store: !ruby/object:Rackamole::Store::MongoDb
|
40
|
+
host: fred
|
41
|
+
port: 10
|
42
|
+
db_name: mole_fred_production
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rackamole
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fernand Galiana
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-21 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -203,6 +203,7 @@ files:
|
|
203
203
|
- spec/rackamole/store/mongo_db_spec.rb
|
204
204
|
- spec/rackamole_spec.rb
|
205
205
|
- spec/spec_helper.rb
|
206
|
+
- spec/test_configs/rackamole_test.yml
|
206
207
|
- tasks/bones.rake
|
207
208
|
- tasks/gem.rake
|
208
209
|
- tasks/git.rake
|