Browse files

initial mysql mmm monitor

  • Loading branch information...
1 parent dade94b commit d75807f0a61b6f4529f4429ddafd1f9f8683dafa @itsderek23 itsderek23 committed Aug 19, 2011
Showing with 49 additions and 0 deletions.
  1. +30 −0 mysql_mmm/mysql_mmm.rb
  2. +19 −0 mysql_mmm/test.rb
View
30 mysql_mmm/mysql_mmm.rb
@@ -0,0 +1,30 @@
+# Monitors Multi-Master Replication Manager for MySQL (MMM), parsing the output of the
+# "mmm_control show" command (http://mysql-mmm.org/mmm1:how-to-use#show).
+#
+# The number of databases in each state is reported. If a db changes state an alert is generated.
+class MySQLMMM < Scout::Plugin
+
+ STATES = %w(ONLINE AWAITING_RECOVERY ADMIN_OFFLINE HARD_OFFLINE REPLICATION_FAIL REPLICATION_DELAY)
+
+ def build_report
+ output = `sudo mmm_control show`
+ reports = Hash.new
+ current_states = Hash.new
+ previous_states = memory(:previous_states)
+ STATES.each { |s| reports[s] = 0 }
+ output.lines.each do |l|
+ STATES.each do |s|
+ if l.include?(s)
+ reports[s] +=1
+ db = l.strip.match(/^\w+/)[0]
+ current_states[db] = s
+ if previous_states and previous_states[db] and previous_states[db] != s
+ alert("#{db} status changed to #{s}", "#{db} state has changed from #{previous_states[db]} to #{s}")
+ end
+ end
+ end
+ end
+ report(reports)
+ remember(:previous_states => current_states)
+ end
+end
View
19 mysql_mmm/test.rb
@@ -0,0 +1,19 @@
+require File.expand_path('../../test_helper.rb', __FILE__)
+require File.expand_path('../mysql_mmm.rb', __FILE__)
+
+
+class MySQLMMMTest < Test::Unit::TestCase
+
+ def setup
+ @options=parse_defaults("mysql_mmm")
+ end
+
+ # TODO
+ def test_success
+ @plugin=MySQLMMM.new(nil,{},{})
+ #@plugin.expects(:`).with("sudo mmm_control show").returns(SHOW).once
+ #res = @plugin.run()
+ assert true
+ end
+
+end

0 comments on commit d75807f

Please sign in to comment.