Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

attempt for slave fix, better connection error handling

  • Loading branch information...
commit bbcb9d3d3f17c7bbb13f94a8af5e817ef5d56b86 1 parent 3cb7feb
@itsderek23 itsderek23 authored
Showing with 4 additions and 3 deletions.
  1. +4 −3 mongo_slow_queries/mongo_slow_queries.rb
View
7 mongo_slow_queries/mongo_slow_queries.rb
@@ -68,7 +68,7 @@ def build_report
# info
selector = { 'millis' => { '$gte' => threshold } }
- cursor = Mongo::Cursor.new(db[Mongo::DB::SYSTEM_PROFILE_COLLECTION], :selector => selector).limit(20).sort([["$natural", "descending"]])
+ cursor = Mongo::Cursor.new(db[Mongo::DB::SYSTEM_PROFILE_COLLECTION], :selector => selector,:slave_ok=>true).limit(20).sort([["$natural", "descending"]])
# reads most recent first
# {"ts"=>Wed Dec 16 02:44:03 UTC 2009, "info"=>"query twitter_follow.system.profile ntoreturn:0 reslen:1236 nscanned:8 \nquery: { query: { millis: { $gte: 5 } }, orderby: { $natural: -1 } } nreturned:8 bytes:1220", "millis"=>57.0}
@@ -88,8 +88,9 @@ def build_report
alert(build_alert(slow_queries))
end
remember(:last_run,Time.now)
- rescue Mongo::MongoDBError => error
- raise error
+ rescue Mongo::ConnectionFailure => error
+ error("Unable to connect to MongoDB","#{error.message}\n\n#{error.backtrace}")
+ return
rescue RuntimeError => error
if error.message =~/Error with profile command.+unauthorized/i
error("Invalid MongoDB Authentication", "The username/password for your MongoDB database are incorrect")
Please sign in to comment.
Something went wrong with that request. Please try again.