Skip to content
Browse files

Optional mysql command, adding error message when command isn't found

  • Loading branch information...
1 parent 44e3d20 commit f085564e4682bff43fbcb9b5be005a0e22aef14b @itsderek23 itsderek23 committed
Showing with 13 additions and 4 deletions.
  1. +13 −4 mysql_query_statistics/mysql_query_statistics.rb
View
17 mysql_query_statistics/mysql_query_statistics.rb
@@ -12,6 +12,10 @@ class MysqlQueryStatistics < Scout::Plugin
name: MySQL password
notes: Specify the password to connect with
attributes: password
+ mysql_command:
+ name: MySQL Command
+ notes: "The default works on most systems unless the mysql executable isn't in the Cron environment's path. If this is the case, specify the full path to the mysql command."
+ default: mysql
host:
name: MySQL host
notes: Specify something other than 'localhost' to connect via TCP
@@ -29,6 +33,8 @@ class MysqlConnectionError < Exception
end
def build_report
+ @mysql_command = option(:mysql_command) || "mysql"
+
mysql_status = mysql_query('SHOW /*!50002 GLOBAL */ STATUS')
report(:max_used_connections => mysql_status['Max_used_connections'])
@@ -42,9 +48,12 @@ def build_report
end
end
counter(:total, total, :per => :second)
-
- rescue MysqlConnectionError => e
- error("Unable to connect to MySQL",e.message)
+ rescue Exception => e
+ if e.message =~ /command not found|No such/
+ error("MySQL Command not found","mysql may not be in Cron's PATH as the mysql command was not found at #{@mysql_command}. Try using the full path to mysql: #{`which mysql`}.\n\nError Message: #{e.message}")
+ else
+ raise
+ end
end
private
@@ -57,7 +66,7 @@ def get_option(opt_name)
# Executes a mysql query via the 'mysql' command. Returns a Hash of variable names and their values.
def mysql_query(query)
- result = `mysql #{connection_options} -e '#{query}' --batch 2>&1`
+ result = `#{@mysql_command} #{connection_options} -e '#{query}' --batch 2>&1`
if $?.success?
output = {}
result.split(/\n/).each do |line|

0 comments on commit f085564

Please sign in to comment.
Something went wrong with that request. Please try again.