Permalink
Browse files

Added mongo stats and server status plugins.

  • Loading branch information...
1 parent 7c73ca0 commit ca76c3103eddd99de5899b155740bbc8734ced2e @jnunemaker committed Jul 14, 2010
Showing with 89 additions and 15 deletions.
  1. +23 −15 mongodb/{mongodb_ops.rb → mongo_ops.rb}
  2. +39 −0 mongodb/mongo_server_status.rb
  3. +27 −0 mongodb/mongo_stats.rb
@@ -1,4 +1,4 @@
-class MongoDBOps < Scout::Plugin
+class MongoOpsPlugin < Scout::Plugin
OPTIONS=<<-EOS
path_to_db_yml:
label: Path to database.yml
@@ -15,7 +15,8 @@ def build_report
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)
+
+ stats = db.command('serverStatus' => 1)
op_inserts = stats['opcounters']['insert']
op_queries = stats['opcounters']['query']
@@ -24,25 +25,32 @@ def build_report
op_get_mores = stats['opcounters']['getmore']
op_commands = stats['opcounters']['command']
- original_inserts = memory(:op_inserts) || 0
- original_queries = memory(:op_queries) || 0
- original_updates = memory(:op_updates) || 0
- original_deletes = memory(:op_deletes) || 0
- original_get_mores = memory(:op_get_mores) || 0
- original_commands = memory(:op_commands) || 0
+ 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(:inserts => op_inserts - previous_inserts)
+ report(:queries => op_queries - previous_queries)
+ report(:updates => op_updates - previous_updates)
+ report(:deletes => op_deletes - previous_deletes)
+ report(:get_mores => op_get_mores - previous_get_mores)
+ report(: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)
-
- report(:inserts => op_inserts - original_inserts)
- report(:queries => op_queries - original_queries)
- report(:updates => op_updates - original_updates)
- report(:deletes => op_deletes - original_deletes)
- report(:get_mores => op_get_mores - original_get_mores)
- report(:commands => op_commands - original_commands)
end
end
@@ -0,0 +1,39 @@
+class MongoServerStatusPlugin < Scout::Plugin
+ OPTIONS=<<-EOS
+ path_to_db_yml:
+ label: Path to database.yml
+ notes: For example: /path/to/myapp/current/config/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)
+
+ report(:btree_accesses => stats['indexCounters']['btree']['accesses'])
+ report(:btree_hits => stats['indexCounters']['btree']['hits'])
+ report(:btree_misses => stats['indexCounters']['btree']['misses'])
+ report(:btree_resets => stats['indexCounters']['btree']['resets'])
+ report(:btree_miss_ratio => stats['indexCounters']['btree']['missRatio'])
+ report(:global_lock_total_time => stats['globalLock']['totalTime'])
+ report(:global_lock_lock_time => stats['globalLock']['lockTime'])
+ report(:global_lock_ratio => stats['globalLock']['ratio'])
+ report(:background_flushes_total => stats['backgroundFlushing']['flushes'])
+ report(:background_flushes_total_ms => stats['backgroundFlushing']['total_ms'])
+ report(:background_flushes_average_ms => stats['backgroundFlushing']['average_ms'])
+ report(:background_flushes_last_ms => stats['backgroundFlushing']['last_ms'])
+
+ report(:mem_bits => stats['mem']['bits']) if stats['mem'] && stats['mem']['bits']
+ report(:mem_resident => stats['mem']['resident']) if stats['mem'] && stats['mem']['resident']
+ report(:mem_virtual => stats['mem']['virtual']) if stats['mem'] && stats['mem']['virtual']
+ report(:mem_mapped => stats['mem']['mapped']) if stats['mem'] && stats['mem']['mapped']
+ end
+end
@@ -0,0 +1,27 @@
+class MongoStatsPlugin < Scout::Plugin
+ OPTIONS=<<-EOS
+ path_to_db_yml:
+ label: Path to database.yml
+ notes: For example: /path/to/myapp/current/config/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.stats
+
+ report(:objects => stats['objects'])
+ report(:data_size => stats['dataSize'])
+ report(:storage_size => stats['storageSize'])
+ report(:indexes => stats['indexes'])
+ report(:index_size => stats['indexSize'])
+ end
+end

0 comments on commit ca76c31

Please sign in to comment.