Class: OkComputer::ElasticsearchCheck
- Defined in:
- lib/ok_computer/built_in_checks/elasticsearch_check.rb
Overview
This class performs a health check on an elasticsearch cluster using the cluster health API.
It reports the cluster’s name, number of nodes, and status (green, yellow, or red). A cluster status of red is reported as a failure, since this means one or more primary shards are unavailable. Note that the app may still be able to perform some queries on the available indices/shards.
Constant Summary
Constants inherited from HttpCheck
Constants inherited from Check
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
Attributes inherited from HttpCheck
#basic_auth_password, #basic_auth_username, #request_timeout, #url
Attributes inherited from Check
#failure_occurred, #message, #registrant_name, #time
Instance Method Summary collapse
-
#check ⇒ Object
Public: Return the status of the elasticsearch cluster.
-
#cluster_health ⇒ Object
Returns a hash from elasticsearch’s cluster health API.
-
#initialize(host, request_timeout = 5) ⇒ ElasticsearchCheck
constructor
Public: Initialize a new elasticsearch check.
Methods inherited from HttpCheck
#basic_auth_options, #parse_url, #perform_request
Methods inherited from Check
#<=>, #clear, #mark_failure, #mark_message, #run, #success?, #to_json, #to_text, #with_benchmarking
Constructor Details
#initialize(host, request_timeout = 5) ⇒ ElasticsearchCheck
Public: Initialize a new elasticsearch check.
host - The hostname of elasticsearch request_timeout - How long to wait to connect before timing out. Defaults to 5 seconds.
16 17 18 19 |
# File 'lib/ok_computer/built_in_checks/elasticsearch_check.rb', line 16 def initialize(host, request_timeout = 5) @host = URI(host) super("#{host}/_cluster/health", request_timeout) end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
10 11 12 |
# File 'lib/ok_computer/built_in_checks/elasticsearch_check.rb', line 10 def host @host end |
Instance Method Details
#check ⇒ Object
Public: Return the status of the elasticsearch cluster
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ok_computer/built_in_checks/elasticsearch_check.rb', line 22 def check cluster_health = self.cluster_health if cluster_health[:status] == 'red' mark_failure end "Connected to elasticseach cluster '#{cluster_health[:cluster_name]}', #{cluster_health[:number_of_nodes]} nodes, status '#{cluster_health[:status]}'" rescue => e mark_failure "Error: '#{e}'" end |
#cluster_health ⇒ Object
Returns a hash from elasticsearch’s cluster health API
36 37 38 39 |
# File 'lib/ok_computer/built_in_checks/elasticsearch_check.rb', line 36 def cluster_health response = perform_request JSON.parse(response, symbolize_names: true) end |