Permalink
Browse files

Fixing connection issues for Mongo gem v1.4 and greater, using raw JS…

…ON output for slow queries in alert
  • Loading branch information...
1 parent 205bbca commit 3f6dd8ec706b0e69dd401d3aa321ad5e1c97ff7f @itsderek23 itsderek23 committed Jan 17, 2012
Showing with 6 additions and 16 deletions.
  1. +1 −0 .gitignore
  2. +5 −16 mongo_slow_queries/mongo_slow_queries.rb
View
@@ -4,3 +4,4 @@
.idea
active_website_monitor
.bundle/
+.rvmrc
@@ -57,13 +57,8 @@ def build_report
else
threshold = threshold_str.to_i
end
-
- connection = if Gem::Version.new(Mongo::VERSION) < Gem::Version.new('1.1.5')
- Mongo::Connection.new(server,option("port").to_i)
- else
- Mongo::ReplSetConnection.new([server,option("port").to_i], :read_secondary => true)
- end
- db = connection.db(database)
+
+ db = Mongo::Connection.new(server, option("port").to_i).db(database)
db.authenticate(option(:username), option(:password)) if !option(:username).to_s.empty?
enable_profiling(db)
@@ -106,13 +101,7 @@ def build_report
def build_alert(slow_queries)
subj = "Maximum Query Time exceeded on #{slow_queries.size} #{slow_queries.size > 1 ? 'queries' : 'query'}"
-
- body = String.new
- slow_queries.each do |sq|
- body << "<strong>#{sq["millis"]} millisec query on #{sq['ts']}:</strong>\n"
- body << sq['info']
- body << "\n\n"
- end # slow_queries.each
- {:subject => subj, :body => body}
- end # build_alert
+ {:subject => subj, :body => slow_queries.to_json}
+ end
+
end

0 comments on commit 3f6dd8e

Please sign in to comment.