Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

56 lines (47 sloc) 2.064 kB
class MongoOpsPlugin < Scout::Plugin
OPTIONS=<<-EOS
path_to_db_yml:
label: Path to database.yml
rails_env:
label: Rails Environment
default: production
EOS
needs 'mongo', 'yaml'
def build_report
config = YAML::load_file(option('path_to_db_yml'))[option('rails_env')]
connection = Mongo::Connection.new(config['host'], config['port'])
db = connection.db(config['database'])
db.authenticate(config['username'], config['password']) unless config['username'].nil?
stats = db.command('serverStatus' => 1)
op_inserts = stats['opcounters']['insert']
op_queries = stats['opcounters']['query']
op_updates = stats['opcounters']['update']
op_deletes = stats['opcounters']['delete']
op_get_mores = stats['opcounters']['getmore']
op_commands = stats['opcounters']['command']
previous_inserts = memory(:op_inserts) || 0
previous_queries = memory(:op_queries) || 0
previous_updates = memory(:op_updates) || 0
previous_deletes = memory(:op_deletes) || 0
previous_get_mores = memory(:op_get_mores) || 0
previous_commands = memory(:op_commands) || 0
report(:op_inserts => op_inserts - previous_inserts)
report(:op_queries => op_queries - previous_queries)
report(:op_updates => op_updates - previous_updates)
report(:op_deletes => op_deletes - previous_deletes)
report(:op_get_mores => op_get_mores - previous_get_mores)
report(:op_commands => op_commands - previous_commands)
report(:total_inserts => op_inserts)
report(:total_queries => op_queries)
report(:total_updates => op_updates)
report(:total_deletes => op_deletes)
report(:total_get_mores => op_get_mores)
report(:total_commands => op_commands)
remember(:op_inserts, op_inserts)
remember(:op_queries, op_queries)
remember(:op_updates, op_updates)
remember(:op_deletes, op_deletes)
remember(:op_get_mores, op_get_mores)
remember(:op_commands, op_commands)
end
end
Jump to Line
Something went wrong with that request. Please try again.