Permalink
Browse files

Adding MySQL variable tracking plugins.

  • Loading branch information...
1 parent 916194f commit 00c3285dc2b2ea71504acef917ed7c6d507f3519 @dougbarth dougbarth committed Apr 12, 2012
@@ -0,0 +1,67 @@
+class MysqlBufferPoolStats < Scout::Plugin
+ OPTIONS=<<-EOS
+ user:
+ name: MySQL username
+ notes: Specify the username to connect with
+ default: root
+ password:
+ name: MySQL password
+ notes: Specify the password to connect with
+ attributes: password
+ host:
+ name: MySQL host
+ notes: Specify something other than 'localhost' to connect via TCP
+ default: localhost
+ port:
+ name: MySQL port
+ notes: Specify the port to connect to MySQL with (if nonstandard)
+ socket:
+ name: MySQL socket
+ notes: Specify the location of the MySQL socket
+ EOS
+
+ needs 'mysql'
+
+ def build_report
+ # get_option returns nil if the option value is blank
+ user = get_option(:user) || 'root'
+ password = get_option(:password)
+ host = get_option(:host)
+ port = get_option(:port)
+ socket = get_option(:socket)
+
+ mysql = Mysql.connect(host, user, password, nil, (port.nil? ? nil : port.to_i), socket)
+ mysql_status = {}
+ result = mysql.query('SHOW /*!50002 GLOBAL */ STATUS')
+ result.each do |row|
+ mysql_status[row.first] = row.last.to_i
+ end
+ result.free
+
+ counters = %w(Innodb_buffer_pool_pages_flushed
+ Innodb_buffer_pool_read_ahead_rnd
+ Innodb_buffer_pool_read_ahead_seq
+ Innodb_buffer_pool_read_requests
+ Innodb_buffer_pool_reads
+ Innodb_buffer_pool_wait_free
+ Innodb_buffer_pool_write_requests)
+ counters.each do |counter|
+ counter(counter, mysql_status[counter], :per => :second)
+ end
+
+ gauges = %w(Innodb_buffer_pool_pages_data
+ Innodb_buffer_pool_pages_dirty
+ Innodb_buffer_pool_pages_free
+ Innodb_buffer_pool_pages_misc
+ Innodb_buffer_pool_pages_total)
+ gauges.each do |gauge|
+ report(gauge => mysql_status[gauge])
+ end
+ end
+
+ # Returns nil if an empty string
+ def get_option(opt_name)
+ val = option(opt_name)
+ return (val.is_a?(String) and val.strip == '') ? nil : val
+ end
+end
@@ -0,0 +1,61 @@
+class MysqlExtraStats < Scout::Plugin
+ OPTIONS=<<-EOS
+ user:
+ name: MySQL username
+ notes: Specify the username to connect with
+ default: root
+ password:
+ name: MySQL password
+ notes: Specify the password to connect with
+ attributes: password
+ host:
+ name: MySQL host
+ notes: Specify something other than 'localhost' to connect via TCP
+ default: localhost
+ port:
+ name: MySQL port
+ notes: Specify the port to connect to MySQL with (if nonstandard)
+ socket:
+ name: MySQL socket
+ notes: Specify the location of the MySQL socket
+ EOS
+
+ needs 'mysql'
+
+ def build_report
+ # get_option returns nil if the option value is blank
+ user = get_option(:user) || 'root'
+ password = get_option(:password)
+ host = get_option(:host)
+ port = get_option(:port)
+ socket = get_option(:socket)
+
+ mysql = Mysql.connect(host, user, password, nil, (port.nil? ? nil : port.to_i), socket)
+ mysql_status = {}
+ result = mysql.query('SHOW /*!50002 GLOBAL */ STATUS')
+ result.each do |row|
+ mysql_status[row.first] = row.last.to_i
+ end
+ result.free
+
+ counters = %w(Aborted_clients
+ Opened_tables
+ Select_full_join
+ Select_scan
+ Threads_created
+ Innodb_data_fsyncs
+ Innodb_os_log_fsyncs
+ Created_tmp_tables
+ Created_tmp_disk_tables
+ )
+ counters.each do |counter|
+ counter(counter, mysql_status[counter], :per => :second)
+ end
+ end
+
+ # Returns nil if an empty string
+ def get_option(opt_name)
+ val = option(opt_name)
+ return (val.is_a?(String) and val.strip == '') ? nil : val
+ end
+end
@@ -0,0 +1,52 @@
+class MysqlHandlerStats < Scout::Plugin
+ OPTIONS=<<-EOS
+ user:
+ name: MySQL username
+ notes: Specify the username to connect with
+ default: root
+ password:
+ name: MySQL password
+ notes: Specify the password to connect with
+ attributes: password
+ host:
+ name: MySQL host
+ notes: Specify something other than 'localhost' to connect via TCP
+ default: localhost
+ port:
+ name: MySQL port
+ notes: Specify the port to connect to MySQL with (if nonstandard)
+ socket:
+ name: MySQL socket
+ notes: Specify the location of the MySQL socket
+ EOS
+
+ needs 'mysql'
+
+ def build_report
+ # get_option returns nil if the option value is blank
+ user = get_option(:user) || 'root'
+ password = get_option(:password)
+ host = get_option(:host)
+ port = get_option(:port)
+ socket = get_option(:socket)
+
+ mysql = Mysql.connect(host, user, password, nil, (port.nil? ? nil : port.to_i), socket)
+ mysql_status = {}
+ result = mysql.query('SHOW /*!50002 GLOBAL */ STATUS')
+ result.each do |row|
+ mysql_status[row.first] = row.last.to_i
+ end
+ result.free
+
+ mysql_status.each do |key, value|
+ next unless key =~ /^Handler_/
+ counter(key, value, :per => :second)
+ end
+ end
+
+ # Returns nil if an empty string
+ def get_option(opt_name)
+ val = option(opt_name)
+ return (val.is_a?(String) and val.strip == '') ? nil : val
+ end
+end

0 comments on commit 00c3285

Please sign in to comment.