Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
334 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
require 'mongo_mapper' | |||
require 'activesupport' | |||
|
|||
Rackamole.require_all_libs_relative_to(__FILE__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,13 @@ | |||
module Rackamole::Mongo | |||
class Feature | |||
include MongoMapper::Document | |||
|
|||
key :controller, String, :required => false | |||
key :action , String, :required => false | |||
key :context , String, :required => false | |||
key :app_name , String, :required => true | |||
timestamps! | |||
|
|||
many :logs, :class_name => 'Rackamole::Mongo::Log' | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,22 @@ | |||
module Rackamole::Mongo | |||
class Log | |||
include MongoMapper::Document | |||
|
|||
key :feature_id , String, :required => true | |||
key :perf_issue , Boolean, :required => true, :default => false | |||
key :type , String , :required => true, :default => 'Feature' | |||
key :ip , String , :required => true | |||
key :browser , String , :required => true | |||
key :method , String , :required => true | |||
key :path , String , :required => true | |||
key :url , String , :required => true | |||
|
|||
key :user_id , Integer, :required => false, :default => -1 | |||
key :user_name , String , :required => false, :default => "Unknown" | |||
key :session , Hash , :required => false | |||
key :router_info, Hash , :required => false | |||
timestamps! | |||
|
|||
belongs_to :feature, :class_name => 'Rackamole::Mongo::Feature' | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
Rackamole.require_all_libs_relative_to(__FILE__) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,77 @@ | |||
require 'mongo' | |||
|
|||
include Mongo | |||
|
|||
# TODO !! Need to deal with auth | |||
module Rackamole | |||
module Store | |||
# Mongo adapter. Stores mole info in a mongo database. | |||
class MongoDb | |||
|
|||
def initialize( options={} ) | |||
opts = default_options.merge( options ) | |||
MongoMapper.connection = Connection.new( opts[:host], opts[:port], :logger => opts[:logger] ) | |||
MongoMapper.database = opts[:database] | |||
end | |||
|
|||
# clear out db content ( used in testing... ) | |||
def reset! | |||
Rackamole::Mongo::Feature.delete_all | |||
Rackamole::Mongo::Log.delete_all | |||
end | |||
|
|||
# Dump mole info to logger | |||
def mole( arguments ) | |||
return if arguments.empty? | |||
args = arguments.clone | |||
|
|||
app_name = args.delete( :app_name ) | |||
|
|||
if args[:route_info] | |||
controller = args[:route_info][:controller] | |||
action = args[:route_info][:action] | |||
feature = Rackamole::Mongo::Feature.find_or_create_by_app_name_and_controller_and_action( app_name, controller, action ) | |||
else | |||
context = args[:path] | |||
feature = Rackamole::Mongo::Feature.find_or_create_by_app_name_and_context( app_name, context ) | |||
end | |||
log_feature( feature, args ) | |||
rescue => mole_boom | |||
$stderr.puts "MOLE STORE CRAPPED OUT -- #{mole_boom}" | |||
$stderr.puts mole_boom.backtrace.join( "\n " ) | |||
end | |||
|
|||
# ======================================================================= | |||
private | |||
|
|||
# Set up mongo default options ie localhost host, default mongo port and | |||
# the database being mole_mdb | |||
def default_options | |||
{ | |||
:host => 'localhost', | |||
:port => 27017, | |||
:database => 'mole_mdb' | |||
} | |||
end | |||
|
|||
# Insert a new feature in the db | |||
def log_feature( feature, args ) | |||
type = 'Feature' | |||
type = 'Exception' if args[:stack] | |||
type = 'Performance' if args[:performance] | |||
|
|||
attrs = { | |||
:type => type, | |||
:feature => feature, | |||
:created_at => Time.now, | |||
:updated_at => Time.now | |||
} | |||
|
|||
args.each do |k,v| | |||
attrs[k] = v | |||
end | |||
Rackamole::Mongo::Log.create!( attrs ) | |||
end | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.