Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mysql] fix replication service check. #2603

Merged
merged 2 commits into from
Jun 15, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions checks.d/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ def _collect_metrics(self, host, db, tags, options, queries):
if _is_affirmative(options.get('replication', False)):
# Get replica stats
results.update(self._get_replica_stats(db))
results.update(self._get_slave_status(db, performance_schema_enabled))
results.update(self._get_slave_status(db))
metrics.update(REPLICA_VARS)

# get slave running form global status page
Expand All @@ -535,17 +535,17 @@ def _collect_metrics(self, host, db, tags, options, queries):
# slaves will only be collected iff user has PROCESS privileges.
slaves = self._collect_scalar('Slaves_connected', results)

if slave_running is not None:
if slave_running.lower().strip() == 'on':
if self._is_master(slaves, binlog_running): # master
if slaves > 0 and binlog_running:
slave_running_status = AgentCheck.OK
else:
slave_running_status = AgentCheck.CRITICAL
elif slaves or binlog_running:
if slaves and slaves > 0 and binlog_running:
slave_running_status = AgentCheck.WARNING
elif slave_running: # slave (or standalone)
if slave_running.lower().strip() == 'on':
slave_running_status = AgentCheck.OK
else:
slave_running_status = AgentCheck.WARNING
else:
slave_running_status = AgentCheck.CRITICAL
Copy link
Member Author

@truthbk truthbk Jun 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if on standalone, they should obviously disable replication on the YAML. But this would still make sense.

else: # slave - with no `Slave_running`
# MySQL 5.7.x might not have 'Slave_running'. See: https://bugs.mysql.com/bug.php?id=78544
# look at replica vars collected at the top of if-block
if self._version_compatible(db, host, "5.7.0"):
Expand Down Expand Up @@ -598,6 +598,14 @@ def _collect_metrics(self, host, db, tags, options, queries):
self.warning("Maximum number (%s) of custom queries reached. Skipping the rest."
% self.MAX_CUSTOM_QUERIES)


def _is_master(self, slaves, binlog):
if slaves > 0 or binlog:
return True

return False


def _collect_metadata(self, db, host):
version = self._get_version(db, host)
self.service_metadata('version', ".".join(version))
Expand Down Expand Up @@ -849,7 +857,7 @@ def _get_replica_stats(self, db):
self.warning("Privileges error getting replication status (must grant REPLICATION CLIENT): %s" % str(e))
return {}

def _get_slave_status(self, db, nonblocking=False):
def _get_slave_status(self, db, nonblocking=True):
try:
with closing(db.cursor()) as cursor:
# querying threads instead of PROCESSLIST to avoid mutex impact on
Expand Down