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

[consul] Added maintenance status for metrics #2496

Closed
wants to merge 1 commit into from
Closed
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
21 changes: 20 additions & 1 deletion checks.d/consul.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ConsulCheck(AgentCheck):
'passing': AgentCheck.OK,
'warning': AgentCheck.WARNING,
'critical': AgentCheck.CRITICAL,
'maintenance': "maintenance"
}

def __init__(self, name, init_config, agentConfig, instances=None):
Expand Down Expand Up @@ -242,6 +243,7 @@ def check(self, instance):

# {'up': 0, 'passing': 0, 'warning': 0, 'critical': 0}
node_status = defaultdict(int)
node_status['maintenance'] = 0

for node in nodes_with_service:
# The node_id is n['Node']['Node']
Expand All @@ -258,6 +260,8 @@ def check(self, instance):
found_critical = False
found_warning = False
found_serf_health = False
found_Maint = False
found_maint_critical = False

for check in node['Checks']:
if check['CheckID'] == 'serfHealth':
Expand All @@ -278,10 +282,25 @@ def check(self, instance):
elif check['Status'] == 'warning':
found_warning = True
# Keep looping in case there is a critical status

if check['CheckID'] == '_node_maintenance':
found_Maint = True

# For backwards compatibility, the "up" node_status is computed
# based on the total # of nodes 'running' as part of the service.

# If the serfHealth is `critical` it means the Consul agent isn't even responding,
# and we don't register the node as `up`

if check['Status'] == 'critical':
found_maint_critical = True

# Increment the counters based on what was found in Checks
# `critical` checks override `warning`s, and if neither are found, register the node as `passing`
if found_critical:
if found_maint_critical:
node_status['maintenance'] += 1
nodes_to_service_status[node_id]["maintenance"] += 1
elif found_critical:
node_status['critical'] += 1
nodes_to_service_status[node_id]["critical"] += 1
elif found_warning:
Expand Down