bin/metrics-es-cluster.rb in sensu-plugins-elasticsearch-0.4.0 vs bin/metrics-es-cluster.rb in sensu-plugins-elasticsearch-0.4.1
- old
+ new
@@ -120,35 +120,50 @@
health
end
def acquire_document_count
document_count = get_es_resource('/_stats/docs')
- document_count['_all']['total']['docs']['count']
+ count = document_count['_all']['total']
+ if count.empty?
+ return 0
+ else
+ return count['docs']['count']
+ end
end
def acquire_cluster_metrics
cluster_stats = get_es_resource('/_cluster/stats')
cluster_metrics = Hash.new { |h, k| h[k] = {} }
cluster_metrics['fs']['total_in_bytes'] = cluster_stats['nodes']['fs']['total_in_bytes']
cluster_metrics['fs']['free_in_bytes'] = cluster_stats['nodes']['fs']['free_in_bytes']
cluster_metrics['fs']['store_in_bytes'] = cluster_stats['indices']['store']['size_in_bytes']
cluster_metrics['fielddata']['memory_size_in_bytes'] = cluster_stats['indices']['fielddata']['memory_size_in_bytes']
cluster_metrics['fielddata']['evictions'] = cluster_stats['indices']['fielddata']['evictions']
- cluster_metrics['filter_cache']['memory_size_in_bytes'] = cluster_stats['indices']['filter_cache']['memory_size_in_bytes']
- cluster_metrics['filter_cache']['evictions'] = cluster_stats['indices']['filter_cache']['evictions']
+
+ # Elasticsearch changed the name filter_cache to query_cache in 2.0+
+ cache_name = Gem::Version.new(acquire_es_version) < Gem::Version.new('2.0.0') ? 'filter_cache' : 'query_cache'
+
+ cluster_metrics[cache_name]['memory_size_in_bytes'] = cluster_stats['indices'][cache_name]['memory_size_in_bytes']
+ cluster_metrics[cache_name]['evictions'] = cluster_stats['indices'][cache_name]['evictions']
cluster_metrics['mem'] = cluster_stats['nodes']['jvm']['mem']
+
if config[:enable_percolate]
cluster_metrics['percolate']['total'] = cluster_stats['indices']['percolate']['total']
cluster_metrics['percolate']['time_in_millis'] = cluster_stats['indices']['percolate']['time_in_millis']
cluster_metrics['percolate']['queries'] = cluster_stats['indices']['percolate']['queries']
end
cluster_metrics
end
def acquire_allocation_status
cluster_config = get_es_resource('/_cluster/settings')
- %w(none new_primaries primaries all).index(cluster_config['transient']['cluster']['routing']['allocation']['enable'])
+ transient_settings = cluster_config['transient']
+ if transient_settings.empty?
+ return nil
+ else
+ return %w(none new_primaries primaries all).index(transient_settings['cluster']['routing']['allocation']['enable'])
+ end
end
def run
if config[:allow_non_master] || master?
acquire_health.each do |k, v|
@@ -158,10 +173,10 @@
cluster_metric[1].each do |k, v|
output(config[:scheme] + '.' + cluster_metric[0] + '.' + k, v)
end
end
output(config[:scheme] + '.document_count', acquire_document_count)
- output(config[:scheme] + '.allocation_status', acquire_allocation_status)
+ output(config[:scheme] + '.allocation_status', acquire_allocation_status) unless acquire_allocation_status.nil?
end
ok
end
end