diff --git a/README.md b/README.md index bcf609c..09091fd 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,21 @@ You should then configure the MySQL plugin: HeartbeatTable "percona.heartbeat" (if using pt-heartbeat to track slave lag) Verbose false (default: false) - + + +You can use a defaults file instead of the user and password, which will also allow +use of a nonstandard socket location. + + + Import mysql + + Host "localhost" + Port 3306 + DefaultsFile "/root/.my.cnf-foo" + + + +The plugin is not configurable for multiple instances per host. ## Metrics @@ -323,4 +337,4 @@ For versions of MySQL with support for it and where enabled, `INFORMATION_SCHEMA response_time_count.14 ## License -MIT (http://www.opensource.org/licenses/mit-license.php) \ No newline at end of file +MIT (http://www.opensource.org/licenses/mit-license.php) diff --git a/mysql.py b/mysql.py index c5182a2..f0349f4 100644 --- a/mysql.py +++ b/mysql.py @@ -34,6 +34,7 @@ 'Password': '', 'HeartbeatTable': '', 'Verbose': False, + 'DefaultsFile': '' } MYSQL_STATUS_VARS = { @@ -285,12 +286,20 @@ } def get_mysql_conn(): - return MySQLdb.connect( - host=MYSQL_CONFIG['Host'], - port=MYSQL_CONFIG['Port'], - user=MYSQL_CONFIG['User'], - passwd=MYSQL_CONFIG['Password'] - ) + # if defaults file is set, use it vice user and password + if MYSQL_CONFIG['DefaultsFile']: + return MySQLdb.connect( + host=MYSQL_CONFIG['Host'], + port=MYSQL_CONFIG['Port'], + read_default_file=MYSQL_CONFIG['DefaultsFile'] + ) + else: + return MySQLdb.connect( + host=MYSQL_CONFIG['Host'], + port=MYSQL_CONFIG['Port'], + user=MYSQL_CONFIG['User'], + passwd=MYSQL_CONFIG['Password'] + ) def mysql_query(conn, query): cur = conn.cursor(MySQLdb.cursors.DictCursor)