-
Notifications
You must be signed in to change notification settings - Fork 9
/
elasticsearch_
executable file
·208 lines (171 loc) · 5.81 KB
/
elasticsearch_
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/usr/bin/env ruby
require 'rubygems'
require 'net/http'
require 'json'
#%# family=auto
#%# capabilities=autoconf suggest
@host = ENV.member?('host') ? ENV['host']: "localhost"
@node = ENV.member?('node') ? ENV['node']: "_local"
@port = ENV.member?('port') ? ENV['port']: 9200
@user = ENV.member?('user') ? ENV['user']: ""
@pass = ENV.member?('pass') ? ENV['pass']: ""
def fetch(resource)
uri = URI("http://" + @host + ":" + @port.to_s + resource)
req = Net::HTTP::Get.new(uri)
unless @user.empty?
req.basic_auth @user, @pass
end
response = Net::HTTP.start(uri.hostname, uri.port) {|http|
http.request(req)
}
return JSON.parse(response.body)
end
err = IO.new(2, "w")
mode = $0.gsub /.*\/elasticsearch_/, ""
if ARGV[0] == "autoconf"
begin
node_encode = URI.escape(@node)
nodes_d = fetch('/_nodes/'+node_encode);
puts "yes"
exit 0
rescue
puts "no"
exit 0
end
end
if ARGV[0] == "suggest"
puts "jvm"
puts "gc"
puts "gc_time"
puts "cache"
puts "docs"
puts "ops"
puts "store"
exit 0
end
if ARGV[0] == "config"
case mode
when "jvm"
puts "graph_title elasticsearch JVM heap"
puts "graph_category elasticsearch"
puts "graph_args --base 1024 -l 0"
puts "graph_vlabel Bytes"
puts "graph_order used committed"
puts "used.label used bytes";
puts "used.draw AREA";
puts "committed.label committed bytes";
puts "committed.draw LINE2";
when "gc"
puts "graph_title elasticsearch GC collection count"
puts "graph_category elasticsearch"
puts "graph_args --base 1000 -l 0"
puts "graph_vlabel Collections per second"
puts "graph_order count"
puts "count.label GC count";
puts "count.type DERIVE";
puts "count.min 0";
puts "count.draw LINE2";
when "gc_time"
puts "graph_title elasticsearch GC collection time"
puts "graph_category elasticsearch"
puts "graph_args --base 1000 -l 0"
puts "graph_vlabel Running time (ms)"
puts "graph_order time"
puts "time.label Running time (ms)";
puts "time.type DERIVE";
puts "time.min 0";
puts "time.draw LINE2";
when "cache"
puts "graph_title elasticsearch cache"
puts "graph_category elasticsearch"
puts "graph_args --base 1024 -l 0"
puts "graph_vlabel Bytes"
puts "graph_order field filter"
puts "field.label field cache";
puts "field.draw LINE2";
puts "filter.label query cache";
puts "filter.draw LINE2";
when "docs"
puts "graph_title elasticsearch docs"
puts "graph_category elasticsearch"
puts "graph_args --base 1000 -l 0"
puts "graph_vlabel Documents"
puts "graph_order count"
puts "count.label document count";
puts "count.draw LINE2";
when "ops"
puts "graph_title elasticsearch index operations"
puts "graph_category elasticsearch"
puts "graph_args --base 1000 -l 0"
puts "graph_vlabel Operations per second"
puts "graph_order index get search delete"
puts "index.label index";
puts "index.type DERIVE";
puts "index.min 0";
puts "index.draw LINE2";
puts "get.label get";
puts "get.type DERIVE";
puts "get.min 0";
puts "get.draw LINE2";
puts "search.label search";
puts "search.type DERIVE";
puts "search.min 0";
puts "search.draw LINE2";
puts "delete.label delete";
puts "delete.type DERIVE";
puts "delete.min 0";
puts "delete.draw LINE2";
when "store"
puts "graph_title elasticsearch store"
puts "graph_category elasticsearch"
puts "graph_args --base 1024 -l 0"
puts "graph_vlabel Bytes"
puts "graph_order size"
puts "size.label store size";
puts "size.draw LINE2";
end
exit 0
end
data = {};
begin
node_encode = URI.escape(@node)
stats = fetch('/_nodes/'+node_encode+'/stats');
rescue
err.puts "Fetch error"
exit 1
end
node_stats = stats['nodes'].values.first
if node_stats.nil?
err.puts "No node found"
exit 1
end
data['jvm'] = {
"used" => node_stats['jvm']['mem']['heap_used_in_bytes'],
"committed" => node_stats['jvm']['mem']['heap_committed_in_bytes']
}
data['gc'] = {
"count" => node_stats['jvm']['gc']['collectors'].inject(0) {|sum, collector| sum += collector.last['collection_count']}
}
data['gc_time'] = {
"time" => node_stats['jvm']['gc']['collectors'].inject(0) {|sum, collector| sum += collector.last['collection_time_in_millis']}
}
data['cache'] = {
"field" => node_stats['indices']['fielddata']['memory_size_in_bytes'],
"filter" => node_stats['indices']['query_cache']['memory_size_in_bytes']
}
data['docs'] = {
"count" => node_stats['indices']['docs']['count']
}
data['ops'] = {
"index" => node_stats['indices']['indexing']['index_total'],
"get" => node_stats['indices']['get']['total'],
"search" => node_stats['indices']['search']['query_total'],
"delete" => node_stats['indices']['indexing']['delete_total']
}
data['store'] = {
"size" => node_stats['indices']['store']['size_in_bytes']
}
# print result
data[mode].each do |k, v|
printf "#{k}.value %s\n", v
end