elasticsearch plugin fixes and optimization
Ilya committed
Jul 19, 2017 at 17:43 UTC
2c9c396a4455e1427611907ef4656743ebe007c2
1 file changed
+200
-209
python.d/elasticsearch.chart.py
+200
-209
@@ -2,15 +2,16 @@
2
# Description: elastic search node stats netdata python.d module
3
# Author: l2isbad
4
5
-from base import UrlService
5
+from collections import namedtuple
6
+from json import loads
7
from socket import gethostbyname, gaierror
8
+from threading import Thread
9
try:
10
from queue import Queue
11
except ImportError:
12
from Queue import Queue
11
-from threading import Thread
12
-from collections import namedtuple
13
-from json import loads
13
+
14
+from base import UrlService
15
16
# default module values (can be overridden per job in `config`)
17
# update_every = 2
@@ -18,71 +19,71 @@ update_every = 5
19
priority = 60000
20
retries = 60
21
21
-METHODS = namedtuple('METHODS', ['get_data_function', 'url'])
22
+METHODS = namedtuple('METHODS', ['get_data', 'url', 'run'])
23
24
NODE_STATS = [
24
- ('indices.search.fetch_current', None, None),
25
- ('indices.search.fetch_total', None, None),
26
- ('indices.search.query_current', None, None),
27
- ('indices.search.query_total', None, None),
28
- ('indices.search.query_time_in_millis', None, None),
29
- ('indices.search.fetch_time_in_millis', None, None),
30
- ('indices.indexing.index_total', 'indexing_index_total', None),
31
- ('indices.indexing.index_current', 'indexing_index_current', None),
32
- ('indices.indexing.index_time_in_millis', 'indexing_index_time_in_millis', None),
33
- ('indices.refresh.total', 'refresh_total', None),
34
- ('indices.refresh.total_time_in_millis', 'refresh_total_time_in_millis', None),
35
- ('indices.flush.total', 'flush_total', None),
36
- ('indices.flush.total_time_in_millis', 'flush_total_time_in_millis', None),
37
- ('jvm.gc.collectors.young.collection_count', 'young_collection_count', None),
38
- ('jvm.gc.collectors.old.collection_count', 'old_collection_count', None),
39
- ('jvm.gc.collectors.young.collection_time_in_millis', 'young_collection_time_in_millis', None),
40
- ('jvm.gc.collectors.old.collection_time_in_millis', 'old_collection_time_in_millis', None),
41
- ('jvm.mem.heap_used_percent', 'jvm_heap_percent', None),
42
- ('jvm.mem.heap_committed_in_bytes', 'jvm_heap_commit', None),
43
- ('thread_pool.bulk.queue', 'bulk_queue', None),
44
- ('thread_pool.bulk.rejected', 'bulk_rejected', None),
45
- ('thread_pool.index.queue', 'index_queue', None),
46
- ('thread_pool.index.rejected', 'index_rejected', None),
47
- ('thread_pool.search.queue', 'search_queue', None),
48
- ('thread_pool.search.rejected', 'search_rejected', None),
49
- ('thread_pool.merge.queue', 'merge_queue', None),
50
- ('thread_pool.merge.rejected', 'merge_rejected', None),
51
- ('indices.fielddata.memory_size_in_bytes', 'index_fdata_memory', None),
52
- ('indices.fielddata.evictions', None, None),
53
- ('breakers.fielddata.tripped', None, None),
54
- ('http.current_open', 'http_current_open', None),
55
- ('transport.rx_size_in_bytes', 'transport_rx_size_in_bytes', None),
56
- ('transport.tx_size_in_bytes', 'transport_tx_size_in_bytes', None),
57
- ('process.max_file_descriptors', None, None),
58
- ('process.open_file_descriptors', None, None)
25
+ 'indices.search.fetch_current',
26
+ 'indices.search.fetch_total',
27
+ 'indices.search.query_current',
28
+ 'indices.search.query_total',
29
+ 'indices.search.query_time_in_millis',
30
+ 'indices.search.fetch_time_in_millis',
31
+ 'indices.indexing.index_total',
32
+ 'indices.indexing.index_current',
33
+ 'indices.indexing.index_time_in_millis',
34
+ 'indices.refresh.total',
35
+ 'indices.refresh.total_time_in_millis',
36
+ 'indices.flush.total'
37
+ 'indices.flush.total_time_in_millis',
38
+ 'jvm.gc.collectors.young.collection_count',
39
+ 'jvm.gc.collectors.old.collection_count',
40
+ 'jvm.gc.collectors.young.collection_time_in_millis',
41
+ 'jvm.gc.collectors.old.collection_time_in_millis',
42
+ 'jvm.mem.heap_used_percent',
43
+ 'jvm.mem.heap_committed_in_bytes',
44
+ 'thread_pool.bulk.queue'
45
+ 'thread_pool.bulk.rejected',
46
+ 'thread_pool.index.queue',
47
+ 'thread_pool.index.rejected',
48
+ 'thread_pool.search.queue',
49
+ 'thread_pool.search.rejected',
50
+ 'thread_pool.merge.queue',
51
+ 'thread_pool.merge.rejected',
52
+ 'indices.fielddata.memory_size_in_bytes',
53
+ 'indices.fielddata.evictions',
54
+ 'breakers.fielddata.tripped',
55
+ 'http.current_open',
56
+ 'transport.rx_size_in_bytes',
57
+ 'transport.tx_size_in_bytes',
58
+ 'process.max_file_descriptors',
59
+ 'process.open_file_descriptors'
60
]
61
62
CLUSTER_STATS = [
62
- ('nodes.count.data_only', 'count_data_only', None),
63
- ('nodes.count.master_data', 'count_master_data', None),
64
- ('nodes.count.total', 'count_total', None),
65
- ('nodes.count.master_only', 'count_master_only', None),
66
- ('nodes.count.client', 'count_client', None),
67
- ('indices.docs.count', 'docs_count', None),
68
- ('indices.query_cache.hit_count', 'query_cache_hit_count', None),
69
- ('indices.query_cache.miss_count', 'query_cache_miss_count', None),
70
- ('indices.store.size_in_bytes', 'store_size_in_bytes', None),
71
- ('indices.count', 'indices_count', None),
72
- ('indices.shards.total', 'shards_total', None)
63
+ 'nodes.count.data_only',
64
+ 'nodes.count.master_data',
65
+ 'nodes.count.total',
66
+ 'nodes.count.master_only',
67
+ 'nodes.count.client',
68
+ 'indices.docs.count',
69
+ 'indices.query_cache.hit_count',
70
+ 'indices.query_cache.miss_count',
71
+ 'indices.store.size_in_bytes',
72
+ 'indices.count',
73
+ 'indices.shards.total'
74
]
75
76
HEALTH_STATS = [
76
- ('number_of_nodes', 'health_number_of_nodes', None),
77
- ('number_of_data_nodes', 'health_number_of_data_nodes', None),
78
- ('number_of_pending_tasks', 'health_number_of_pending_tasks', None),
79
- ('number_of_in_flight_fetch', 'health_number_of_in_flight_fetch', None),
80
- ('active_shards', 'health_active_shards', None),
81
- ('relocating_shards', 'health_relocating_shards', None),
82
- ('unassigned_shards', 'health_unassigned_shards', None),
83
- ('delayed_unassigned_shards', 'health_delayed_unassigned_shards', None),
84
- ('initializing_shards', 'health_initializing_shards', None),
85
- ('active_shards_percent_as_number', 'health_active_shards_percent_as_number', None)
77
+ 'number_of_nodes',
78
+ 'number_of_data_nodes',
79
+ 'number_of_pending_tasks',
80
+ 'number_of_in_flight_fetch',
81
+ 'active_shards',
82
+ 'relocating_shards',
83
+ 'unassigned_shards',
84
+ 'delayed_unassigned_shards',
85
+ 'initializing_shards',
86
+ 'active_shards_percent_as_number'
87
]
88
89
LATENCY = {
@@ -93,139 +94,141 @@ LATENCY = {
94
{'total': 'fetch_total',
95
'spent_time': 'fetch_time_in_millis'},
96
'indexing_latency':
96
- {'total': 'indexing_index_total',
97
- 'spent_time': 'indexing_index_time_in_millis'},
97
+ {'total': 'indices_indexing_index_total',
98
+ 'spent_time': 'indices_indexing_index_time_in_millis'},
99
'flushing_latency':
99
- {'total': 'flush_total',
100
- 'spent_time': 'flush_total_time_in_millis'}
100
+ {'total': 'indices_flush_total',
101
+ 'spent_time': 'indices_flush_total_time_in_millis'}
102
}
103
104
# charts order (can be overridden if you want less charts, or different order)
104
-ORDER = ['search_perf_total', 'search_perf_current', 'search_perf_time', 'search_latency', 'index_perf_total',
105
- 'index_perf_current', 'index_perf_time', 'index_latency', 'jvm_mem_heap', 'jvm_gc_count',
106
- 'jvm_gc_time', 'host_metrics_file_descriptors', 'host_metrics_http', 'host_metrics_transport',
107
- 'thread_pool_qr_q', 'thread_pool_qr_r', 'fdata_cache', 'fdata_ev_tr', 'cluster_health_status',
108
- 'cluster_health_nodes', 'cluster_health_shards', 'cluster_stats_nodes', 'cluster_stats_query_cache',
109
- 'cluster_stats_docs', 'cluster_stats_store', 'cluster_stats_indices_shards']
105
+ORDER = ['search_performance_total', 'search_performance_current', 'search_performance_time',
106
+ 'search_latency', 'index_performance_total', 'index_performance_current', 'index_performance_time',
107
+ 'index_latency', 'jvm_mem_heap', 'jvm_gc_count', 'jvm_gc_time', 'host_metrics_file_descriptors',
108
+ 'host_metrics_http', 'host_metrics_transport', 'thread_pool_queued', 'thread_pool_rejected',
109
+ 'fielddata_cache', 'fielddata_evictions_tripped', 'cluster_health_status', 'cluster_health_nodes',
110
+ 'cluster_health_shards', 'cluster_stats_nodes', 'cluster_stats_query_cache', 'cluster_stats_docs',
111
+ 'cluster_stats_store', 'cluster_stats_indices_shards']
112
113
CHARTS = {
112
- 'search_perf_total': {
114
+ 'search_performance_total': {
115
'options': [None, 'Queries And Fetches', 'number of', 'search performance',
114
- 'es.search_query_total', 'stacked'],
116
+ 'elastic.search_performance_total', 'stacked'],
117
'lines': [
116
- ['query_total', 'queries', 'incremental'],
117
- ['fetch_total', 'fetches', 'incremental']
118
+ ['indices_search_query_total', 'queries', 'incremental'],
119
+ ['indices_search_fetch_total', 'fetches', 'incremental']
120
]},
119
- 'search_perf_current': {
121
+ 'search_performance_current': {
122
'options': [None, 'Queries and Fetches In Progress', 'number of', 'search performance',
121
- 'es.search_query_current', 'stacked'],
123
+ 'elastic.search_performance_current', 'stacked'],
124
'lines': [
123
- ['query_current', 'queries', 'absolute'],
124
- ['fetch_current', 'fetches', 'absolute']
125
+ ['indices_search_query_current', 'queries', 'absolute'],
126
+ ['indices_search_fetch_current', 'fetches', 'absolute']
127
]},
126
- 'search_perf_time': {
128
+ 'search_performance_time': {
129
'options': [None, 'Time Spent On Queries And Fetches', 'seconds', 'search performance',
128
- 'es.search_time', 'stacked'],
130
+ 'elastic.search_performance_time', 'stacked'],
131
'lines': [
130
- ['query_time_in_millis', 'query', 'incremental', 1, 1000],
131
- ['fetch_time_in_millis', 'fetch', 'incremental', 1, 1000]
132
+ ['indices_search_query_time_in_millis', 'query', 'incremental', 1, 1000],
133
+ ['indices_search_fetch_time_in_millis', 'fetch', 'incremental', 1, 1000]
134
]},
135
'search_latency': {
134
- 'options': [None, 'Query And Fetch Latency', 'ms', 'search performance', 'es.search_latency', 'stacked'],
136
+ 'options': [None, 'Query And Fetch Latency', 'ms', 'search performance', 'elastic.search_latency', 'stacked'],
137
'lines': [
138
['query_latency', 'query', 'absolute', 1, 1000],
139
['fetch_latency', 'fetch', 'absolute', 1, 1000]
140
]},
139
- 'index_perf_total': {
141
+ 'index_performance_total': {
142
'options': [None, 'Indexed Documents, Index Refreshes, Index Flushes To Disk', 'number of',
141
- 'indexing performance', 'es.index_performance_total', 'stacked'],
143
+ 'indexing performance', 'elastic.index_performance_total', 'stacked'],
144
'lines': [
143
- ['indexing_index_total', 'indexed', 'incremental'],
144
- ['refresh_total', 'refreshes', 'incremental'],
145
- ['flush_total', 'flushes', 'incremental']
145
+ ['indices_indexing_index_total', 'indexed', 'incremental'],
146
+ ['indices_refresh_total', 'refreshes', 'incremental'],
147
+ ['indices_flush_total', 'flushes', 'incremental']
148
]},
147
- 'index_perf_current': {
149
+ 'index_performance_current': {
150
'options': [None, 'Number Of Documents Currently Being Indexed', 'currently indexed',
149
- 'indexing performance', 'es.index_performance_current', 'stacked'],
151
+ 'indexing performance', 'elastic.index_performance_current', 'stacked'],
152
'lines': [
151
- ['indexing_index_current', 'documents', 'absolute']
153
+ ['indices_indexing_index_current', 'documents', 'absolute']
154
]},
153
- 'index_perf_time': {
155
+ 'index_performance_time': {
156
'options': [None, 'Time Spent On Indexing, Refreshing, Flushing', 'seconds', 'indexing performance',
155
- 'es.search_time', 'stacked'],
157
+ 'elastic.index_performance_time', 'stacked'],
158
'lines': [
157
- ['indexing_index_time_in_millis', 'indexing', 'incremental', 1, 1000],
158
- ['refresh_total_time_in_millis', 'refreshing', 'incremental', 1, 1000],
159
- ['flush_total_time_in_millis', 'flushing', 'incremental', 1, 1000]
159
+ ['indices_indexing_index_time_in_millis', 'indexing', 'incremental', 1, 1000],
160
+ ['indices_refresh_total_time_in_millis', 'refreshing', 'incremental', 1, 1000],
161
+ ['indices_flush_total_time_in_millis', 'flushing', 'incremental', 1, 1000]
162
]},
163
'index_latency': {
164
'options': [None, 'Indexing And Flushing Latency', 'ms', 'indexing performance',
163
- 'es.index_latency', 'stacked'],
165
+ 'elastic.index_latency', 'stacked'],
166
'lines': [
167
['indexing_latency', 'indexing', 'absolute', 1, 1000],
168
['flushing_latency', 'flushing', 'absolute', 1, 1000]
169
]},
170
'jvm_mem_heap': {
171
'options': [None, 'JVM Heap Currently in Use/Committed', 'percent/MB', 'memory usage and gc',
170
- 'es.jvm_heap', 'area'],
172
+ 'elastic.jvm_heap', 'area'],
173
'lines': [
172
- ['jvm_heap_percent', 'inuse', 'absolute'],
173
- ['jvm_heap_commit', 'commit', 'absolute', -1, 1048576]
174
+ ['jvm_mem_heap_used_percent', 'inuse', 'absolute'],
175
+ ['jvm_mem_heap_committed_in_bytes', 'commit', 'absolute', -1, 1048576]
176
]},
177
'jvm_gc_count': {
176
- 'options': [None, 'Garbage Collections', 'counts', 'memory usage and gc', 'es.gc_count', 'stacked'],
178
+ 'options': [None, 'Garbage Collections', 'counts', 'memory usage and gc', 'elastic.gc_count', 'stacked'],
179
'lines': [
178
- ['young_collection_count', 'young', 'incremental'],
179
- ['old_collection_count', 'old', 'incremental']
180
+ ['jvm_gc_collectors_young_collection_count', 'young', 'incremental'],
181
+ ['jvm_gc_collectors_old_collection_count', 'old', 'incremental']
182
]},
183
'jvm_gc_time': {
182
- 'options': [None, 'Time Spent On Garbage Collections', 'ms', 'memory usage and gc', 'es.gc_time', 'stacked'],
184
+ 'options': [None, 'Time Spent On Garbage Collections', 'ms', 'memory usage and gc',
185
+ 'elastic.gc_time', 'stacked'],
186
'lines': [
184
- ['young_collection_time_in_millis', 'young', 'incremental'],
185
- ['old_collection_time_in_millis', 'old', 'incremental']
187
+ ['jvm_gc_collectors_young_collection_time_in_millis', 'young', 'incremental'],
188
+ ['jvm_gc_collectors_old_collection_time_in_millis', 'old', 'incremental']
189
]},
187
- 'thread_pool_qr_q': {
190
+ 'thread_pool_queued': {
191
'options': [None, 'Number Of Queued Threads In Thread Pool', 'queued threads', 'queues and rejections',
189
- 'es.thread_pool_queued', 'stacked'],
192
+ 'elastic.thread_pool_queued', 'stacked'],
193
'lines': [
191
- ['bulk_queue', 'bulk', 'absolute'],
192
- ['index_queue', 'index', 'absolute'],
193
- ['search_queue', 'search', 'absolute'],
194
- ['merge_queue', 'merge', 'absolute']
194
+ ['thread_pool_bulk_queue', 'bulk', 'absolute'],
195
+ ['thread_pool_index_queue', 'index', 'absolute'],
196
+ ['thread_pool_search_queue', 'search', 'absolute'],
197
+ ['thread_pool_merge_queue', 'merge', 'absolute']
198
]},
196
- 'thread_pool_qr_r': {
199
+ 'thread_pool_rejected': {
200
'options': [None, 'Rejected Threads In Thread Pool', 'rejected threads', 'queues and rejections',
198
- 'es.thread_pool_rejected', 'stacked'],
201
+ 'elastic.thread_pool_rejected', 'stacked'],
202
'lines': [
200
- ['bulk_rejected', 'bulk', 'absolute'],
201
- ['index_rejected', 'index', 'absolute'],
202
- ['search_rejected', 'search', 'absolute'],
203
- ['merge_rejected', 'merge', 'absolute']
203
+ ['thread_pool_bulk_rejected', 'bulk', 'absolute'],
204
+ ['thread_pool_index_rejected', 'index', 'absolute'],
205
+ ['thread_pool_search_rejected', 'search', 'absolute'],
206
+ ['thread_pool_merge_rejected', 'merge', 'absolute']
207
]},
205
- 'fdata_cache': {
206
- 'options': [None, 'Fielddata Cache', 'MB', 'fielddata cache', 'es.fdata_cache', 'line'],
208
+ 'fielddata_cache': {
209
+ 'options': [None, 'Fielddata Cache', 'MB', 'fielddata cache', 'elastic.fielddata_cache', 'line'],
210
'lines': [
208
- ['index_fdata_memory', 'cache', 'absolute', 1, 1048576]
211
+ ['indices_fielddata_memory_size_in_bytes', 'cache', 'absolute', 1, 1048576]
212
]},
210
- 'fdata_ev_tr': {
213
+ 'fielddata_evictions_tripped': {
214
'options': [None, 'Fielddata Evictions And Circuit Breaker Tripped Count', 'number of events',
212
- 'fielddata cache', 'es.evictions_tripped', 'line'],
215
+ 'fielddata cache', 'elastic.fielddata_evictions_tripped', 'line'],
216
'lines': [
214
- ['evictions', None, 'incremental'],
215
- ['tripped', None, 'incremental']
217
+ ['indices_fielddata_evictions', 'evictions', 'incremental'],
218
+ ['indices_fielddata_tripped', 'tripped', 'incremental']
219
]},
220
'cluster_health_nodes': {
221
'options': [None, 'Nodes And Tasks Statistics', 'units', 'cluster health API',
219
- 'es.cluster_health_nodes', 'stacked'],
222
+ 'elastic.cluster_health_nodes', 'stacked'],
223
'lines': [
221
- ['health_number_of_nodes', 'nodes', 'absolute'],
222
- ['health_number_of_data_nodes', 'data_nodes', 'absolute'],
223
- ['health_number_of_pending_tasks', 'pending_tasks', 'absolute'],
224
- ['health_number_of_in_flight_fetch', 'in_flight_fetch', 'absolute']
224
+ ['number_of_nodes', 'nodes', 'absolute'],
225
+ ['number_of_data_nodes', 'data_nodes', 'absolute'],
226
+ ['number_of_pending_tasks', 'pending_tasks', 'absolute'],
227
+ ['number_of_in_flight_fetch', 'in_flight_fetch', 'absolute']
228
]},
229
'cluster_health_status': {
230
'options': [None, 'Cluster Status', 'status', 'cluster health API',
228
- 'es.cluster_health_status', 'area'],
231
+ 'elastic.cluster_health_status', 'area'],
232
'lines': [
233
['status_green', 'green', 'absolute'],
234
['status_red', 'red', 'absolute'],
@@ -236,67 +239,67 @@ CHARTS = {
239
]},
240
'cluster_health_shards': {
241
'options': [None, 'Shards Statistics', 'shards', 'cluster health API',
239
- 'es.cluster_health_shards', 'stacked'],
242
+ 'elastic.cluster_health_shards', 'stacked'],
243
'lines': [
241
- ['health_active_shards', 'active_shards', 'absolute'],
242
- ['health_relocating_shards', 'relocating_shards', 'absolute'],
243
- ['health_unassigned_shards', 'unassigned', 'absolute'],
244
- ['health_delayed_unassigned_shards', 'delayed_unassigned', 'absolute'],
245
- ['health_initializing_shards', 'initializing', 'absolute'],
246
- ['health_active_shards_percent_as_number', 'active_percent', 'absolute']
244
+ ['active_shards', 'active_shards', 'absolute'],
245
+ ['relocating_shards', 'relocating_shards', 'absolute'],
246
+ ['unassigned_shards', 'unassigned', 'absolute'],
247
+ ['delayed_unassigned_shards', 'delayed_unassigned', 'absolute'],
248
+ ['initializing_shards', 'initializing', 'absolute'],
249
+ ['active_shards_percent_as_number', 'active_percent', 'absolute']
250
]},
251
'cluster_stats_nodes': {
252
'options': [None, 'Nodes Statistics', 'nodes', 'cluster stats API',
250
- 'es.cluster_nodes', 'stacked'],
253
+ 'elastic.cluster_nodes', 'stacked'],
254
'lines': [
252
- ['count_data_only', 'data_only', 'absolute'],
253
- ['count_master_data', 'master_data', 'absolute'],
254
- ['count_total', 'total', 'absolute'],
255
- ['count_master_only', 'master_only', 'absolute'],
256
- ['count_client', 'client', 'absolute']
255
+ ['nodes_count_data_only', 'data_only', 'absolute'],
256
+ ['nodes_count_master_data', 'master_data', 'absolute'],
257
+ ['nodes_count_total', 'total', 'absolute'],
258
+ ['nodes_count_master_only', 'master_only', 'absolute'],
259
+ ['nodes_count_client', 'client', 'absolute']
260
]},
261
'cluster_stats_query_cache': {
262
'options': [None, 'Query Cache Statistics', 'queries', 'cluster stats API',
260
- 'es.cluster_query_cache', 'stacked'],
263
+ 'elastic.cluster_query_cache', 'stacked'],
264
'lines': [
262
- ['query_cache_hit_count', 'hit', 'incremental'],
263
- ['query_cache_miss_count', 'miss', 'incremental']
265
+ ['indices_query_cache_hit_count', 'hit', 'incremental'],
266
+ ['indices_query_cache_miss_count', 'miss', 'incremental']
267
]},
268
'cluster_stats_docs': {
269
'options': [None, 'Docs Statistics', 'count', 'cluster stats API',
267
- 'es.cluster_docs', 'line'],
270
+ 'elastic.cluster_docs', 'line'],
271
'lines': [
269
- ['docs_count', 'docs', 'absolute']
272
+ ['indices_docs_count', 'docs', 'absolute']
273
]},
274
'cluster_stats_store': {
275
'options': [None, 'Store Statistics', 'MB', 'cluster stats API',
273
- 'es.cluster_store', 'line'],
276
+ 'elastic.cluster_store', 'line'],
277
'lines': [
275
- ['store_size_in_bytes', 'size', 'absolute', 1, 1048567]
278
+ ['indices_store_size_in_bytes', 'size', 'absolute', 1, 1048567]
279
]},
280
'cluster_stats_indices_shards': {
281
'options': [None, 'Indices And Shards Statistics', 'count', 'cluster stats API',
279
- 'es.cluster_indices_shards', 'stacked'],
282
+ 'elastic.cluster_indices_shards', 'stacked'],
283
'lines': [
284
['indices_count', 'indices', 'absolute'],
282
- ['shards_total', 'shards', 'absolute']
285
+ ['indices_shards_total', 'shards', 'absolute']
286
]},
287
'host_metrics_transport': {
288
'options': [None, 'Cluster Communication Transport Metrics', 'kilobit/s', 'host metrics',
286
- 'es.host_transport', 'area'],
289
+ 'elastic.host_transport', 'area'],
290
'lines': [
291
['transport_rx_size_in_bytes', 'in', 'incremental', 8, 1000],
292
['transport_tx_size_in_bytes', 'out', 'incremental', -8, 1000]
293
]},
294
'host_metrics_file_descriptors': {
295
'options': [None, 'Available File Descriptors In Percent', 'percent', 'host metrics',
293
- 'es.host_descriptors', 'area'],
296
+ 'elastic.host_descriptors', 'area'],
297
'lines': [
298
['file_descriptors_used', 'used', 'absolute', 1, 10]
299
]},
300
'host_metrics_http': {
301
'options': [None, 'Opened HTTP Connections', 'connections', 'host metrics',
299
- 'es.host_http_connections', 'line'],
302
+ 'elastic.host_http_connections', 'line'],
303
'lines': [
304
['http_current_open', 'opened', 'absolute', 1, 1]
305
]}
@@ -310,7 +313,9 @@ class Service(UrlService):
313
self.definitions = CHARTS
314
self.host = self.configuration.get('host')
315
self.port = self.configuration.get('port', 9200)
313
- self.scheme = self.configuration.get('scheme', 'http')
316
+ self.url = '{scheme}://{host}:{port}'.format(scheme=self.configuration.get('scheme', 'http'),
317
+ host=self.host,
318
+ port=self.port)
319
self.latency = dict()
320
self.methods = list()
321
@@ -329,33 +334,19 @@ class Service(UrlService):
334
self.error(str(error))
335
return False
336
332
- scheme = 'http' if self.scheme == 'http' else 'https'
333
- # Add handlers (auth, self signed cert accept)
334
- self.url = '%s://%s:%s' % (scheme, self.host, self.port)
335
- self.opener = self._build_opener()
337
# Create URL for every Elasticsearch API
337
- url_node_stats = '%s://%s:%s/_nodes/_local/stats' % (scheme, self.host, self.port)
338
- url_cluster_health = '%s://%s:%s/_cluster/health' % (scheme, self.host, self.port)
339
- url_cluster_stats = '%s://%s:%s/_cluster/stats' % (scheme, self.host, self.port)
340
-
341
- user_choice = [bool(self.configuration.get('node_stats', True)),
342
- bool(self.configuration.get('cluster_health', True)),
343
- bool(self.configuration.get('cluster_stats', True))]
344
-
345
- avail_methods = [METHODS(get_data_function=self._get_node_stats_,
346
- url=url_node_stats),
347
- METHODS(get_data_function=self._get_cluster_health_,
348
- url=url_cluster_health),
349
- METHODS(get_data_function=self._get_cluster_stats_,
350
- url=url_cluster_stats)]
338
+ self.methods = [METHODS(get_data=self._get_node_stats,
339
+ url=self.url + '/_nodes/_local/stats',
340
+ run=self.configuration.get('node_stats', True)),
341
+ METHODS(get_data=self._get_cluster_health,
342
+ url=self.url + '/_cluster/health',
343
+ run=self.configuration.get('cluster_health', True)),
344
+ METHODS(get_data=self._get_cluster_stats,
345
+ url=self.url + '/_cluster/stats',
346
+ run=self.configuration.get('cluster_stats', True))]
347
348
# Remove disabled API calls from 'avail methods'
353
- self.methods = [avail_methods[e[0]] for e in enumerate(avail_methods) if user_choice[e[0]]]
354
- data = self._get_data()
355
- if not data:
356
- return False
357
- self._data_from_check = data
358
- return True
349
+ return UrlService.check(self)
350
351
def _get_data(self):
352
threads = list()
@@ -363,7 +354,9 @@ class Service(UrlService):
354
result = dict()
355
356
for method in self.methods:
366
- th = Thread(target=method.get_data_function,
357
+ if not method.run:
358
+ continue
359
+ th = Thread(target=method.get_data,
360
args=(queue, method.url))
361
th.start()
362
threads.append(th)
@@ -374,7 +367,7 @@ class Service(UrlService):
367
368
return result or None
369
377
- def _get_cluster_health_(self, queue, url):
370
+ def _get_cluster_health(self, queue, url):
371
"""
372
Format data received from http request
373
:return: dict
@@ -387,7 +380,7 @@ class Service(UrlService):
380
381
data = loads(raw_data)
382
to_netdata = fetch_data_(raw_data=data,
390
- metrics_list=HEALTH_STATS)
383
+ metrics=HEALTH_STATS)
384
385
to_netdata.update({'status_green': 0, 'status_red': 0, 'status_yellow': 0,
386
'status_foo1': 0, 'status_foo2': 0, 'status_foo3': 0})
@@ -396,7 +389,7 @@ class Service(UrlService):
389
390
return queue.put(to_netdata)
391
399
- def _get_cluster_stats_(self, queue, url):
392
+ def _get_cluster_stats(self, queue, url):
393
"""
394
Format data received from http request
395
:return: dict
@@ -409,11 +402,11 @@ class Service(UrlService):
402
403
data = loads(raw_data)
404
to_netdata = fetch_data_(raw_data=data,
412
- metrics_list=CLUSTER_STATS)
405
+ metrics=CLUSTER_STATS)
406
407
return queue.put(to_netdata)
408
416
- def _get_node_stats_(self, queue, url):
409
+ def _get_node_stats(self, queue, url):
410
"""
411
Format data received from http request
412
:return: dict
@@ -428,23 +421,23 @@ class Service(UrlService):
421
422
node = list(data['nodes'].keys())[0]
423
to_netdata = fetch_data_(raw_data=data['nodes'][node],
431
- metrics_list=NODE_STATS)
424
+ metrics=NODE_STATS)
425
426
# Search, index, flush, fetch performance latency
427
for key in LATENCY:
428
try:
436
- to_netdata[key] = self.find_avg_(total=to_netdata[LATENCY[key]['total']],
437
- spent_time=to_netdata[LATENCY[key]['spent_time']],
438
- key=key)
429
+ to_netdata[key] = self.find_avg(total=to_netdata[LATENCY[key]['total']],
430
+ spent_time=to_netdata[LATENCY[key]['spent_time']],
431
+ key=key)
432
except KeyError:
433
continue
441
- if 'open_file_descriptors' in to_netdata and 'max_file_descriptors' in to_netdata:
442
- to_netdata['file_descriptors_used'] = round(float(to_netdata['open_file_descriptors'])
443
- / to_netdata['max_file_descriptors'] * 1000)
434
+ if 'process_open_file_descriptors' in to_netdata and 'process_max_file_descriptors' in to_netdata:
435
+ to_netdata['file_descriptors_used'] = round(float(to_netdata['process_open_file_descriptors'])
436
+ / to_netdata['process_max_file_descriptors'] * 1000)
437
438
return queue.put(to_netdata)
439
447
- def find_avg_(self, total, spent_time, key):
440
+ def find_avg(self, total, spent_time, key):
441
if key not in self.latency:
442
self.latency[key] = dict(total=total,
443
spent_time=spent_time)
@@ -459,17 +452,15 @@ class Service(UrlService):
452
return 0
453
454
462
-def fetch_data_(raw_data, metrics_list):
463
- to_netdata = dict()
464
- for metric, new_name, func in metrics_list:
455
+def fetch_data_(raw_data, metrics):
456
+ data = dict()
457
+ for metric in metrics:
458
value = raw_data
466
- for key in metric.split('.'):
467
- try:
468
- value = value[key]
469
- except KeyError:
470
- break
471
- if not isinstance(value, dict) and key:
472
- to_netdata[new_name or key] = value if not func else func(value)
473
-
474
- return to_netdata
475
-
459
+ metrics_list = metric.split('.')
460
+ try:
461
+ for m in metrics_list:
462
+ value = value[m]
463
+ except KeyError:
464
+ continue
465
+ data['_'.join(metrics_list)] = value
466
+ return data