Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 56 lines (47 sloc) 2.064 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
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
Something went wrong with that request. Please try again.