class OkComputer::ElasticsearchCheck

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.

Attributes

host[R]

Public Class Methods

new(host, request_timeout = 5) click to toggle source

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.

Calls superclass method
# 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

Public Instance Methods

check() click to toggle source

Public: Return the status of the elasticsearch cluster

# 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

  mark_message "Connected to elasticseach cluster '#{cluster_health[:cluster_name]}', #{cluster_health[:number_of_nodes]} nodes, status '#{cluster_health[:status]}'"
rescue => e
  mark_failure
  mark_message "Error: '#{e}'"
end
cluster_health() click to toggle source

Returns a hash from elasticsearch’s cluster health API

# 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