Skip to content

Commit

Permalink
[mysql] fix innodb engine check.
Browse files Browse the repository at this point in the history
[mysql] if the version is too old, the stats will probable be unavailable anyways.

[mysql] disable innodb metrics, respond better to unavailable innodb metrics.

[mysql] catch NotSupportedError - possible exception when querying older MySQLs.

[mysql] adding flag description to yaml, cleaning query.
  • Loading branch information
truthbk committed Mar 28, 2016
1 parent 78841f5 commit 4bce354
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
22 changes: 14 additions & 8 deletions checks.d/mysql.py
Expand Up @@ -410,7 +410,7 @@ def _collect_metrics(self, host, db, tags, options, queries):
results = self._get_stats_from_status(db)
results.update(self._get_stats_from_variables(db))

if self._is_innodb_engine_enabled(db):
if (not _is_affirmative(options.get('disable_innodb_metrics', False)) and self._is_innodb_engine_enabled(db)):
results.update(self._get_stats_from_innodb_status(db))

innodb_keys = [
Expand Down Expand Up @@ -806,13 +806,18 @@ def _is_innodb_engine_enabled(self, db):
# Whether InnoDB engine is available or not can be found out either
# from the output of SHOW ENGINES or from information_schema.ENGINES
# table. Later is choosen because that involves no string parsing.
with closing(db.cursor()) as cursor:
cursor.execute(
"select engine from information_schema.ENGINES where engine='InnoDB'")
try:
with closing(db.cursor()) as cursor:
cursor.execute(
"select engine from information_schema.ENGINES where engine='InnoDB' and \
support != 'no' and support != 'disabled'"
)

return_val = True if cursor.rowcount > 0 else False
return (cursor.rowcount > 0)

return return_val
except (pymysql.err.InternalError, pymysql.err.OperationalError, pymysql.err.NotSupportedError) as e:
self.warning("Possibly innodb stats unavailable - error querying engines table: %s" % str(e))
return False

def _get_replica_stats(self, db):
try:
Expand Down Expand Up @@ -864,8 +869,9 @@ def _get_stats_from_innodb_status(self, db):
cursor.execute("SHOW /*!50000 ENGINE*/ INNODB STATUS")
innodb_status = cursor.fetchone()
innodb_status_text = innodb_status[2]
except (pymysql.err.InternalError, pymysql.err.OperationalError) as e:
self.warning("Privilege error accessing the INNODB status tables (must grant PROCESS): %s" % str(e))
except (pymysql.err.InternalError, pymysql.err.OperationalError, pymysql.err.NotSupportedError) as e:
self.warning("Privilege error or engine unavailable accessing the INNODB status \
tables (must grant PROCESS): %s" % str(e))
return {}

results = defaultdict(int)
Expand Down
4 changes: 4 additions & 0 deletions conf.d/mysql.yaml.example
Expand Up @@ -17,7 +17,11 @@ instances:
# extra_innodb_metrics: true
# extra_performance_metrics: true
# schema_size_metrics: false
# disable_innodb_metrics: false
#
# NOTE: disable_innodb_metrics should only be used by users with older (unsupported) versions of
# MySQL who do not run/have innodb engine support and may experiment issue otherwise.
# Should this flag be enabled you will only receive a small subset of metrics.
#
# NOTE: extra_performance_metrics will only be reported if `performance_schema` is enabled
# in the MySQL instance and if the version for that instance is >= 5.6.0
Expand Down

0 comments on commit 4bce354

Please sign in to comment.