riemann-elasticsearch 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/riemann-elasticsearch +89 -59
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e1225c22e80a1d45434c03d349b067670190f4f
|
4
|
+
data.tar.gz: bc8a6881c0f6109f7fff364d5cbdb834e713173d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9d07022decd084de14f1dc69d956fc98a6f3c007b3069de18d33b84560d6cda900c06aa5f0b6571988f96cfcfe6dbe675b884a487c19efe0ad1ca6facebba8c
|
7
|
+
data.tar.gz: 276954e703705a80b392a8393f3b5a6e2ecf6546fcf74dea53c8e512eeaac5cd0af5a95110051cc5544b7603acd02795ed43f66f7e01a3f9081842789259e835
|
data/bin/riemann-elasticsearch
CHANGED
@@ -13,6 +13,7 @@ class Riemann::Tools::Elasticsearch
|
|
13
13
|
opt :path_prefix, 'Elasticsearch path prefix for proxied installations e.g. "els" for target http://localhost/els/_cluster/health', default: "/"
|
14
14
|
opt :es_host, 'Elasticsearch host', default: "localhost"
|
15
15
|
opt :es_port, 'Elasticsearch port', type: :int, default: 9200
|
16
|
+
opt :es_search_index, 'Elasticsearch index to fetch search statistics for', default: "_all"
|
16
17
|
|
17
18
|
|
18
19
|
# Handles HTTP connections and GET requests safely
|
@@ -35,90 +36,119 @@ class Riemann::Tools::Elasticsearch
|
|
35
36
|
response
|
36
37
|
end
|
37
38
|
|
38
|
-
def
|
39
|
+
def make_es_url(path)
|
39
40
|
path_prefix = options[:path_prefix]
|
40
41
|
path_prefix[0] = '' if path_prefix[0]=='/'
|
41
42
|
path_prefix[path_prefix.length-1] = '' if path_prefix[path_prefix.length-1]=='/'
|
42
|
-
"http://#{options[:es_host]}:#{options[:es_port]}#{path_prefix.length>0?'/':''}#{path_prefix}
|
43
|
+
"http://#{options[:es_host]}:#{options[:es_port]}#{path_prefix.length>0?'/':''}#{path_prefix}/#{path}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def health_url
|
47
|
+
make_es_url("_cluster/health")
|
43
48
|
end
|
44
49
|
|
45
50
|
def indices_url
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
51
|
+
make_es_url("_stats/index,store")
|
52
|
+
end
|
53
|
+
|
54
|
+
def search_url
|
55
|
+
es_search_index = options[:es_search_index]
|
56
|
+
make_es_url("#{es_search_index}/_stats/search")
|
57
|
+
end
|
58
|
+
|
59
|
+
def is_bad?(response, uri)
|
60
|
+
if response.success?
|
61
|
+
false
|
62
|
+
else
|
63
|
+
report(:host => uri.host,
|
64
|
+
:service => "elasticsearch health",
|
65
|
+
:state => "critical",
|
66
|
+
:description => response.nil? ? "HTTP response is empty!" : "HTTP connection error: #{response.status} - #{response.body}"
|
67
|
+
)
|
68
|
+
end
|
50
69
|
end
|
51
70
|
|
52
71
|
def tick_indices
|
53
72
|
uri = URI(indices_url)
|
54
73
|
response = safe_get(uri)
|
55
74
|
|
56
|
-
return if response.
|
75
|
+
return if response.is_bad?(uri)
|
57
76
|
|
58
|
-
|
59
|
-
|
60
|
-
:service => "elasticsearch health",
|
61
|
-
:state => "critical",
|
62
|
-
:description => "HTTP connection error: #{response.status} - #{response.body}"
|
63
|
-
)
|
64
|
-
else
|
65
|
-
# Assuming that a 200 will give json
|
66
|
-
json = JSON.parse(response.body)
|
77
|
+
# Assuming that a 200 will give json
|
78
|
+
json = JSON.parse(response.body)
|
67
79
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
end
|
80
|
+
json["indices"].each_pair do |k,v|
|
81
|
+
report(:host => uri.host,
|
82
|
+
:service => "elasticsearch index/#{k}/primaries/size_in_bytes",
|
83
|
+
:metric => v["primaries"]["store"]["size_in_bytes"]
|
84
|
+
)
|
85
|
+
report(:host => uri.host,
|
86
|
+
:service => "elasticsearch index/#{k}/total/size_in_bytes",
|
87
|
+
:metric => v["total"]["store"]["size_in_bytes"]
|
88
|
+
)
|
78
89
|
end
|
79
90
|
end
|
80
91
|
|
81
|
-
def
|
82
|
-
|
83
|
-
uri = URI(health_url)
|
92
|
+
def tick_search
|
93
|
+
uri = URI(search_url)
|
84
94
|
response = safe_get(uri)
|
85
95
|
|
86
|
-
return if response.
|
96
|
+
return if response.is_bad?(uri)
|
87
97
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
# Assuming that a 200 will give json
|
96
|
-
json = JSON.parse(response.body)
|
97
|
-
cluster_name = json.delete("cluster_name")
|
98
|
-
cluster_status = json.delete("status")
|
99
|
-
state = case cluster_status
|
100
|
-
when "green"
|
101
|
-
"ok"
|
102
|
-
when "yellow"
|
103
|
-
"warning"
|
104
|
-
when "red"
|
105
|
-
"critical"
|
106
|
-
end
|
98
|
+
es_search_index = options[:es_search_index]
|
99
|
+
# Assuming that a 200 will give json
|
100
|
+
json = JSON.parse(response.body)
|
101
|
+
|
102
|
+
json["_all"].each_pair do |type, data|
|
103
|
+
query = data["search"]["query_time_in_millis"].to_f / data["search"]["query_total"].to_f
|
104
|
+
fetch = data["search"]["fetch_time_in_millis"].to_f / data["search"]["fetch_total"].to_f
|
107
105
|
|
108
106
|
report(:host => uri.host,
|
109
|
-
:service => "elasticsearch
|
110
|
-
:
|
111
|
-
|
107
|
+
:service => "elasticsearch search/#{es_search_index}/query",
|
108
|
+
:metric => query
|
109
|
+
)
|
110
|
+
report(:host => uri.host,
|
111
|
+
:service => "elasticsearch search/#{es_search_index}/fetch",
|
112
|
+
:metric => fetch
|
113
|
+
)
|
114
|
+
end
|
115
|
+
end
|
112
116
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
117
|
+
def tick
|
118
|
+
tick_indices
|
119
|
+
tick_search
|
120
|
+
uri = URI(health_url)
|
121
|
+
response = safe_get(uri)
|
122
|
+
|
123
|
+
return if response.is_bad?(uri)
|
124
|
+
|
125
|
+
# Assuming that a 200 will give json
|
126
|
+
json = JSON.parse(response.body)
|
127
|
+
cluster_name = json.delete("cluster_name")
|
128
|
+
cluster_status = json.delete("status")
|
129
|
+
state = case cluster_status
|
130
|
+
when "green"
|
131
|
+
"ok"
|
132
|
+
when "yellow"
|
133
|
+
"warning"
|
134
|
+
when "red"
|
135
|
+
"critical"
|
136
|
+
end
|
137
|
+
|
138
|
+
report(:host => uri.host,
|
139
|
+
:service => "elasticsearch health",
|
140
|
+
:state => state,
|
141
|
+
:description => "Elasticsearch cluster: #{cluster_name} - #{cluster_status}")
|
142
|
+
|
143
|
+
json.each_pair do |k,v|
|
144
|
+
report(:host => uri.host,
|
145
|
+
:service => "elasticsearch #{k}",
|
146
|
+
:metric => v,
|
147
|
+
:description => "Elasticsearch cluster #{k}"
|
148
|
+
)
|
119
149
|
|
120
|
-
end
|
121
150
|
end
|
151
|
+
|
122
152
|
end
|
123
153
|
|
124
154
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: riemann-elasticsearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gavin Sandie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: riemann-tools
|