riemann-elasticsearch 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/riemann-elasticsearch +89 -59
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a150bc9f0e28b4a26dd6c0a897bfb3d1a484c42c
4
- data.tar.gz: 21cbd6c24b3fb27157300760755fee7373b4d274
3
+ metadata.gz: 7e1225c22e80a1d45434c03d349b067670190f4f
4
+ data.tar.gz: bc8a6881c0f6109f7fff364d5cbdb834e713173d
5
5
  SHA512:
6
- metadata.gz: a79cbb77d1f89e5419d7393e40335dba5635ea3a5f0bcaebd4d56f51a056bfed18714b3bd26e925cfaf2f1f9cca42aa8f181534113d493f62de64f5191c8953b
7
- data.tar.gz: b91194acde151ebdbd02eaa4ed2303a3192291af66459b7ec0812ba8d0c14380eae53693da576c2264f6c143d208dd6c50c23764c1a893066facec0f457d023e
6
+ metadata.gz: e9d07022decd084de14f1dc69d956fc98a6f3c007b3069de18d33b84560d6cda900c06aa5f0b6571988f96cfcfe6dbe675b884a487c19efe0ad1ca6facebba8c
7
+ data.tar.gz: 276954e703705a80b392a8393f3b5a6e2ecf6546fcf74dea53c8e512eeaac5cd0af5a95110051cc5544b7603acd02795ed43f66f7e01a3f9081842789259e835
@@ -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 health_url
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}/_cluster/health"
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
- path_prefix = options[:path_prefix]
47
- path_prefix[0] = '' if path_prefix[0]=='/'
48
- path_prefix[path_prefix.length-1] = '' if path_prefix[path_prefix.length-1]=='/'
49
- "http://#{options[:es_host]}:#{options[:es_port]}#{path_prefix.length>0?'/':''}#{path_prefix}/_stats/index,store"
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.nil?
75
+ return if response.is_bad?(uri)
57
76
 
58
- if response.status != 200
59
- report(:host => uri.host,
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
- json["indices"].each_pair do |k,v|
69
- report(:host => uri.host,
70
- :service => "elasticsearch index/#{k}/primaries/size_in_bytes",
71
- :metric => v["primaries"]["store"]["size_in_bytes"]
72
- )
73
- report(:host => uri.host,
74
- :service => "elasticsearch index/#{k}/total/size_in_bytes",
75
- :metric => v["total"]["store"]["size_in_bytes"]
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 tick
82
- tick_indices
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.nil?
96
+ return if response.is_bad?(uri)
87
97
 
88
- if response.status != 200
89
- report(:host => uri.host,
90
- :service => "elasticsearch health",
91
- :state => "critical",
92
- :description => "HTTP connection error: #{response.status} - #{response.body}"
93
- )
94
- else
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 health",
110
- :state => state,
111
- :description => "Elasticsearch cluster: #{cluster_name} - #{cluster_status}")
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
- json.each_pair do |k,v|
114
- report(:host => uri.host,
115
- :service => "elasticsearch #{k}",
116
- :metric => v,
117
- :description => "Elasticsearch cluster #{k}"
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.1.1
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-09 00:00:00.000000000 Z
11
+ date: 2016-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: riemann-tools