Class: Fluent::Plugin::ElasticsearchStats::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/elasticsearch_stats/client.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

TIMEOUT =
10
USER_AGENT =
'elasticsearch_stats'
LOCAL =
false
CLUSTER_HEALTH_LEVEL =
'cluster'
NODES_STATS_LEVEL =
'cluster'
INDICES_STATS_LEVEL =
'indices'
INDICES =
[:_all]
ALLOWED_CLUSTER_HEALTH_LEVELS =
%i[cluster indices shards].freeze
ALLOWED_NODES_STATS_LEVELS =
%i[nodes indices shards].freeze
ALLOWED_NODES_STATS_METRICS =
%i[
  adaptive_selection
  breaker
  discovery
  fs
  http
  indexing_pressure
  indices
  ingest
  jvm
  os
  process
  repositories
  thread_pool
  transport
].freeze
ALLOWED_INDICES_LEVELS =
%i[cluster indices shards].freeze
ALLOWED_INDICES_METRICS =
%i[
  _all
  completion
  docs
  fielddata
  flush
  get
  indexing
  merge
  query_cache
  refresh
  request_cache
  search
  segments
  store
  translog
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, timeout: TIMEOUT, username: nil, password: nil, user_agent: USER_AGENT, ca_file: nil, verify_ssl: true, log: nil) ⇒ Client

Returns a new instance of Client.



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/fluent/plugin/elasticsearch_stats/client.rb', line 61

def initialize(url:, timeout: TIMEOUT, username: nil, password: nil,
               user_agent: USER_AGENT, ca_file: nil, verify_ssl: true,
               log: nil)
  @url = url
  @timeout = timeout
  @username = username
  @password = password
  @user_agent = user_agent
  @ca_file = ca_file
  @verify_ssl = verify_ssl
  @log = log
end

Instance Attribute Details

#ca_fileObject (readonly)

Returns the value of attribute ca_file.



58
59
60
# File 'lib/fluent/plugin/elasticsearch_stats/client.rb', line 58

def ca_file
  @ca_file
end

#clientObject (readonly)

Returns the value of attribute client.



58
59
60
# File 'lib/fluent/plugin/elasticsearch_stats/client.rb', line 58

def client
  @client
end

#logObject (readonly)

Returns the value of attribute log.



58
59
60
# File 'lib/fluent/plugin/elasticsearch_stats/client.rb', line 58

def log
  @log
end

#passwordObject (readonly)

Returns the value of attribute password.



58
59
60
# File 'lib/fluent/plugin/elasticsearch_stats/client.rb', line 58

def password
  @password
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



58
59
60
# File 'lib/fluent/plugin/elasticsearch_stats/client.rb', line 58

def timeout
  @timeout
end

#urlObject (readonly)

Returns the value of attribute url.



58
59
60
# File 'lib/fluent/plugin/elasticsearch_stats/client.rb', line 58

def url
  @url
end

#user_agentObject (readonly)

Returns the value of attribute user_agent.



58
59
60
# File 'lib/fluent/plugin/elasticsearch_stats/client.rb', line 58

def user_agent
  @user_agent
end

#usernameObject (readonly)

Returns the value of attribute username.



58
59
60
# File 'lib/fluent/plugin/elasticsearch_stats/client.rb', line 58

def username
  @username
end

#verify_sslObject (readonly)

Returns the value of attribute verify_ssl.



58
59
60
# File 'lib/fluent/plugin/elasticsearch_stats/client.rb', line 58

def verify_ssl
  @verify_ssl
end

Instance Method Details

#cluster_health(level: CLUSTER_HEALTH_LEVEL, local: LOCAL) ⇒ Object



75
76
77
78
79
# File 'lib/fluent/plugin/elasticsearch_stats/client.rb', line 75

def cluster_health(level: CLUSTER_HEALTH_LEVEL, local: LOCAL)
  endpoint = '/_cluster/health'
  params = { level: level, local: local, timeout: "#{timeout}s" }
  get(endpoint, params)
end

#cluster_statsObject



82
83
84
85
86
# File 'lib/fluent/plugin/elasticsearch_stats/client.rb', line 82

def cluster_stats
  endpoint = '/_cluster/stats'
  params = { timeout: "#{timeout}s" }
  get(endpoint, params)
end

#danglingObject



107
108
109
110
# File 'lib/fluent/plugin/elasticsearch_stats/client.rb', line 107

def dangling
  endpoint = '/_dangling'
  get(endpoint)
end

#indices_stats(indices: INDICES, level: INDICES_STATS_LEVEL, metrics: nil) ⇒ Object



97
98
99
100
101
102
103
104
# File 'lib/fluent/plugin/elasticsearch_stats/client.rb', line 97

def indices_stats(indices: INDICES, level: INDICES_STATS_LEVEL, metrics: nil)
  indices ||= INDICES
  endpoint = "/_stats"
  endpoint = "/#{indices.join(',')}#{endpoint}" if !indices.nil? && !indices.empty?
  endpoint += "/#{metrics.join(',')}" if metrics&.any?
  params = { level: level }
  get(endpoint, params)
end

#nodes_stats(level: NODES_STATS_LEVEL, metrics: nil) ⇒ Object



89
90
91
92
93
94
# File 'lib/fluent/plugin/elasticsearch_stats/client.rb', line 89

def nodes_stats(level: NODES_STATS_LEVEL, metrics: nil)
  endpoint = '/_nodes/stats'
  endpoint += "/#{metrics.join(',')}" if metrics&.any?
  params = { level: level, timeout: "#{timeout}s" }
  get(endpoint, params)
end