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

RETRY_COUNT =
2
RETRY_DELAY =
5
TIMEOUT =
10
USER_AGENT =
'elasticsearch_stats'
LOCAL =
false
CLUSTER_HEALTH_LEVEL =
'cluster'
NODES_STATS_LEVEL =
'cluster'
INDICES_STATS_LEVEL =
'indices'
INDICES =
[:_all].freeze
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.



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/fluent/plugin/elasticsearch_stats/client.rb', line 65

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.



62
63
64
# File 'lib/fluent/plugin/elasticsearch_stats/client.rb', line 62

def ca_file
  @ca_file
end

#clientObject (readonly)

Returns the value of attribute client.



62
63
64
# File 'lib/fluent/plugin/elasticsearch_stats/client.rb', line 62

def client
  @client
end

#logObject (readonly)

Returns the value of attribute log.



62
63
64
# File 'lib/fluent/plugin/elasticsearch_stats/client.rb', line 62

def log
  @log
end

#passwordObject (readonly)

Returns the value of attribute password.



62
63
64
# File 'lib/fluent/plugin/elasticsearch_stats/client.rb', line 62

def password
  @password
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



62
63
64
# File 'lib/fluent/plugin/elasticsearch_stats/client.rb', line 62

def timeout
  @timeout
end

#urlObject (readonly)

Returns the value of attribute url.



62
63
64
# File 'lib/fluent/plugin/elasticsearch_stats/client.rb', line 62

def url
  @url
end

#user_agentObject (readonly)

Returns the value of attribute user_agent.



62
63
64
# File 'lib/fluent/plugin/elasticsearch_stats/client.rb', line 62

def user_agent
  @user_agent
end

#usernameObject (readonly)

Returns the value of attribute username.



62
63
64
# File 'lib/fluent/plugin/elasticsearch_stats/client.rb', line 62

def username
  @username
end

#verify_sslObject (readonly)

Returns the value of attribute verify_ssl.



62
63
64
# File 'lib/fluent/plugin/elasticsearch_stats/client.rb', line 62

def verify_ssl
  @verify_ssl
end

Instance Method Details

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



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

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_infoObject



78
79
80
81
# File 'lib/fluent/plugin/elasticsearch_stats/client.rb', line 78

def cluster_info
  endpoint = '/'
  get(endpoint)
end

#cluster_statsObject



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

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

#danglingObject



116
117
118
119
# File 'lib/fluent/plugin/elasticsearch_stats/client.rb', line 116

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

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



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

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



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

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