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

Fetch cluster stats, simplify n_mnodes calculation. #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
32 changes: 6 additions & 26 deletions check_elasticsearch
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ class ElasticSearchCheck(NagiosCheck):
es_state = get_json(r'http://%s:%d/%s_cluster/state' %
(host, port, prefix))

# Request cluster 'stats'. We're primarily interested in the
# node counts.
es_clusterstats = get_json(r'http://%s:%d/%s_cluster/stats' %
(host, port, prefix))

# Request a bunch of useful numbers that we export as perfdata.
# Details like the number of get, search, and indexing
# operations come from here.
Expand All @@ -154,32 +159,7 @@ class ElasticSearchCheck(NagiosCheck):

n_nodes = es_health['number_of_nodes']
n_dnodes = es_health['number_of_data_nodes']

# Unlike n_dnodes (the number of data nodes), we must compute
# the number of master-eligible nodes ourselves.
n_mnodes = 0
for esid in es_state['nodes']:
master_elig = True

# ES will never elect 'client' nodes as masters.
try:
master_elig = not (booleanise(
es_state['nodes'][esid]['attributes']
['client']))
except KeyError, e:
if e.args[0] != 'client':
raise

try:
master_elig = (booleanise(
es_state['nodes'][esid]['attributes']
['master']))
except KeyError, e:
if e.args[0] != 'master':
raise

if master_elig:
n_mnodes += 1
n_mnodes = es_clusterstats['nodes']['count']['master_only'] + es_clusterstats['nodes']['count']['master_data']

n_active_shards = es_health['active_shards']
n_relocating_shards = es_health['relocating_shards']
Expand Down