sensu-plugins-elasticsearch 0.0.1.alpha.2

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1f03554c2ea841f45c1663dfa389f661a26f1031
4
+ data.tar.gz: 2d518076bc8c04425d7dca4ed2215f566d7629b9
5
+ SHA512:
6
+ metadata.gz: 1e51afee4f5e95469b6cd7bce666bb642fc00061a0b8163ff77fff3c6afbe2ace24573a6567c2cd9571f77d266006d3787a9685823a890c735bd8813287d8a0b
7
+ data.tar.gz: a7dedea81b52ade0d79e7216f1866bc558695b342e7cf1e981ccf29f59db5cf7932816d2dcd80c6301cb8449a5e18473eed0adc6d510eb13071a0ba885ac6877
checksums.yaml.gz.sig ADDED
@@ -0,0 +1 @@
1
+ 4��9�z�t���Ih��ʂ1�|�[(_����+�I�{/SL6ܧ( ���j��?�`�C�,�b?�,���"�`��B��e���\�5毈����{ u�G����\�dsz`w;'�T���1��F��K���爅lG�W:�cg{���'}@��7�h"��pt �If�Ӑ�jx��4;�V�C��V�22~�a��N��gܖ��S�1�V�����M �zF�yϓ˜r����xT�Y�~ e
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ #### 0.0.1.alpha.1
2
+
3
+ * initial identical functionality to community repos
4
+
5
+ #### 0.0.1.alpha.2
6
+
7
+ * changed check class names where necessary to enforce uniqueness
8
+ * pinned runtime deps
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 devops@yieldbot.com
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ ## Sensu-Plugins-elasticsearch
2
+
3
+ [![Build Status](https://travis-ci.org/sensu-plugins/sensu-plugins-elasticsearch.svg?branch=master)](https://travis-ci.org/sensu-plugins/sensu-plugins-elasticsearch)
4
+ [![Gem Version](https://badge.fury.io/rb/sensu-plugins-elasticsearch.svg)](http://badge.fury.io/rb/sensu-plugins-elasticsearch)
5
+ [![Code Climate](https://codeclimate.com/github/sensu-plugins/sensu-plugins-elasticsearch/badges/gpa.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-elasticsearch)
6
+ [![Test Coverage](https://codeclimate.com/github/sensu-plugins/sensu-plugins-elasticsearch/badges/coverage.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-elasticsearch)
7
+ [![Dependency Status](https://gemnasium.com/sensu-plugins/sensu-plugins-elasticsearch.svg)](https://gemnasium.com/sensu-plugins/sensu-plugins-elasticsearch)
8
+ ## Functionality
9
+ ## Functionality
10
+
11
+ ## Files
12
+ * /bin/check-es-cluster-status
13
+ * /bin/check-es-heap
14
+ * /bin/metrics-es-node-graphite
15
+ * /bin/check-es-file-descriptors
16
+ * /bin/metrics-es-cluster
17
+ * /bin/metrics-es-node
18
+
19
+ ## Usage
20
+
21
+ ## Installation
22
+
23
+ Add the public key (if you haven’t already) as a trusted certificate
24
+
25
+ ```
26
+ gem cert --add <(curl -Ls https://raw.githubusercontent.com/sensu-plugins/sensu-plugins.github.io/master/certs/sensu-plugins.pem)
27
+ gem install sensu-plugins-elasticsearch -P MediumSecurity
28
+ ```
29
+
30
+ You can also download the key from /certs/ within each repository.
31
+
32
+ #### Rubygems
33
+
34
+ `gem install sensu-plugins-elasticsearch`
35
+
36
+ #### Bundler
37
+
38
+ Add *sensu-plugins-disk-checks* to your Gemfile and run `bundle install` or `bundle update`
39
+
40
+ #### Chef
41
+
42
+ Using the Sensu **sensu_gem** LWRP
43
+ ```
44
+ sensu_gem 'sensu-plugins-elasticsearch' do
45
+ options('--prerelease')
46
+ version '0.0.1.alpha.1'
47
+ end
48
+ ```
49
+
50
+ Using the Chef **gem_package** resource
51
+ ```
52
+ gem_package 'sensu-plugins-elasticsearch' do
53
+ options('--prerelease')
54
+ version '0.0.1.alpha.1'
55
+ end
56
+ ```
57
+
58
+ ## Notes
@@ -0,0 +1,111 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-es-cluster-status
4
+ #
5
+ # DESCRIPTION:
6
+ # This plugin checks the ElasticSearch cluster status, using its API.
7
+ # Works with ES 0.9x and ES 1.x
8
+ #
9
+ # OUTPUT:
10
+ # plain text
11
+ #
12
+ # PLATFORMS:
13
+ # Linux
14
+ #
15
+ # DEPENDENCIES:
16
+ # gem: sensu-plugin
17
+ # gem: rest-client
18
+ # gem: json
19
+ #
20
+ # USAGE:
21
+ # #YELLOW
22
+ #
23
+ # NOTES:
24
+ #
25
+ # LICENSE:
26
+ # Copyright 2012 Sonian, Inc <chefs@sonian.net>
27
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
28
+ # for details.
29
+ #
30
+
31
+ require 'sensu-plugin/check/cli'
32
+ require 'rest-client'
33
+ require 'json'
34
+
35
+ #
36
+ # ES Cluster Status
37
+ #
38
+ class ESClusterStatus < Sensu::Plugin::Check::CLI
39
+ option :host,
40
+ description: 'Elasticsearch host',
41
+ short: '-h HOST',
42
+ long: '--host HOST',
43
+ default: 'localhost'
44
+
45
+ option :port,
46
+ description: 'Elasticsearch port',
47
+ short: '-p PORT',
48
+ long: '--port PORT',
49
+ proc: proc(&:to_i),
50
+ default: 9200
51
+
52
+ option :master_only,
53
+ description: 'Use master Elasticsearch server only',
54
+ short: '-m',
55
+ long: '--master-only',
56
+ default: false
57
+
58
+ option :timeout,
59
+ description: 'Sets the connection timeout for REST client',
60
+ short: '-t SECS',
61
+ long: '--timeout SECS',
62
+ proc: proc(&:to_i),
63
+ default: 30
64
+
65
+ def get_es_resource(resource)
66
+ r = RestClient::Resource.new("http://#{config[:host]}:#{config[:port]}/#{resource}", timeout: config[:timeout])
67
+ JSON.parse(r.get)
68
+ rescue Errno::ECONNREFUSED
69
+ critical 'Connection refused'
70
+ rescue RestClient::RequestTimeout
71
+ critical 'Connection timed out'
72
+ rescue Errno::ECONNRESET
73
+ critical 'Connection reset by peer'
74
+ end
75
+
76
+ def acquire_es_version
77
+ info = get_es_resource('/')
78
+ info['version']['number']
79
+ end
80
+
81
+ def master?
82
+ if Gem::Version.new(acquire_es_version) >= Gem::Version.new('1.0.0')
83
+ master = get_es_resource('_cluster/state/master_node')['master_node']
84
+ local = get_es_resource('/_nodes/_local')
85
+ else
86
+ master = get_es_resource('/_cluster/state?filter_routing_table=true&filter_metadata=true&filter_indices=true')['master_node']
87
+ local = get_es_resource('/_cluster/nodes/_local')
88
+ end
89
+ local['nodes'].keys.first == master
90
+ end
91
+
92
+ def acquire_status
93
+ health = get_es_resource('/_cluster/health')
94
+ health['status'].downcase
95
+ end
96
+
97
+ def run
98
+ if !config[:master_only] || master?
99
+ case acquire_status
100
+ when 'green'
101
+ ok 'Cluster is green'
102
+ when 'yellow'
103
+ warning 'Cluster is yellow'
104
+ when 'red'
105
+ critical 'Cluster is red'
106
+ end
107
+ else
108
+ ok 'Not the master'
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,112 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-es-file-descriptors
4
+ #
5
+ # DESCRIPTION:
6
+ # This plugin checks the ElasticSearch file descriptor usage, using its API.
7
+ #
8
+ # OUTPUT:
9
+ # plain text
10
+ #
11
+ # PLATFORMS:
12
+ # Linux
13
+ #
14
+ # DEPENDENCIES:
15
+ # gem: sensu-plugin
16
+ # gem: json
17
+ # gem: rest-client
18
+ #
19
+ # USAGE:
20
+ # #YELLOW
21
+ #
22
+ # NOTES:
23
+ #
24
+ # LICENSE:
25
+ # Author: S. Zachariah Sprackett <zac@sprackett.com>
26
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
27
+ # for details.
28
+ #
29
+
30
+ require 'sensu-plugin/check/cli'
31
+ require 'rest-client'
32
+ require 'json'
33
+
34
+ #
35
+ # ES File Descriptiors
36
+ #
37
+ class ESFileDescriptors < Sensu::Plugin::Check::CLI
38
+ option :host,
39
+ description: 'Elasticsearch host',
40
+ short: '-h HOST',
41
+ long: '--host HOST',
42
+ default: 'localhost'
43
+
44
+ option :port,
45
+ description: 'Elasticsearch port',
46
+ short: '-p PORT',
47
+ long: '--port PORT',
48
+ proc: proc(&:to_i),
49
+ default: 9200
50
+
51
+ option :timeout,
52
+ description: 'Sets the connection timeout for REST client',
53
+ short: '-t SECS',
54
+ long: '--timeout SECS',
55
+ proc: proc(&:to_i),
56
+ default: 30
57
+
58
+ option :critical,
59
+ description: 'Critical percentage of FD usage',
60
+ short: '-c PERCENTAGE',
61
+ proc: proc(&:to_i),
62
+ default: 90
63
+
64
+ option :warning,
65
+ description: 'Warning percentage of FD usage',
66
+ short: '-w PERCENTAGE',
67
+ proc: proc(&:to_i),
68
+ default: 80
69
+
70
+ def get_es_resource(resource)
71
+ r = RestClient::Resource.new("http://#{config[:host]}:#{config[:port]}/#{resource}", timeout: config[:timeout])
72
+ JSON.parse(r.get)
73
+ rescue Errno::ECONNREFUSED
74
+ warning 'Connection refused'
75
+ rescue RestClient::RequestTimeout
76
+ warning 'Connection timed out'
77
+ end
78
+
79
+ def acquire_open_fds
80
+ stats = get_es_resource('/_nodes/_local/stats?process=true')
81
+ begin
82
+ keys = stats['nodes'].keys
83
+ stats['nodes'][keys[0]]['process']['open_file_descriptors'].to_i
84
+ rescue NoMethodError
85
+ warning 'Failed to retrieve open_file_descriptors'
86
+ end
87
+ end
88
+
89
+ def acquire_max_fds
90
+ info = get_es_resource('/_nodes/_local?process=true')
91
+ begin
92
+ keys = info['nodes'].keys
93
+ info['nodes'][keys[0]]['process']['max_file_descriptors'].to_i
94
+ rescue NoMethodError
95
+ warning 'Failed to retrieve max_file_descriptors'
96
+ end
97
+ end
98
+
99
+ def run
100
+ open = acquire_open_fds
101
+ max = acquire_max_fds
102
+ used_percent = ((open.to_f / max.to_f) * 100).to_i
103
+
104
+ if used_percent >= config[:critical]
105
+ critical "fd usage #{used_percent}% exceeds #{config[:critical]}% (#{open}/#{max})"
106
+ elsif used_percent >= config[:warning]
107
+ warning "fd usage #{used_percent}% exceeds #{config[:warning]}% (#{open}/#{max})"
108
+ else
109
+ ok "fd usage at #{used_percent}% (#{open}/#{max})"
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,137 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-es-heap
4
+ #
5
+ # DESCRIPTION:
6
+ # This plugin checks ElasticSearch's Java heap usage using its API.
7
+ #
8
+ # OUTPUT:
9
+ # plain text
10
+ #
11
+ # PLATFORMS:
12
+ # Linux
13
+ #
14
+ # DEPENDENCIES:
15
+ # gem: sensu-plugin
16
+ # gem: rest-client
17
+ # gem: json
18
+ #
19
+ # USAGE:
20
+ # example commands
21
+ #
22
+ # NOTES:
23
+ #
24
+ # LICENSE:
25
+ # Copyright 2012 Sonian, Inc <chefs@sonian.net>
26
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
27
+ # for details.
28
+ #
29
+
30
+ require 'sensu-plugin/check/cli'
31
+ require 'rest-client'
32
+ require 'json'
33
+
34
+ #
35
+ # ES Heap
36
+ #
37
+ class ESHeap < Sensu::Plugin::Check::CLI
38
+ option :host,
39
+ description: 'Elasticsearch host',
40
+ short: '-h HOST',
41
+ long: '--host HOST',
42
+ default: 'localhost'
43
+
44
+ option :port,
45
+ description: 'Elasticsearch port',
46
+ short: '-p PORT',
47
+ long: '--port PORT',
48
+ proc: proc(&:to_i),
49
+ default: 9200
50
+
51
+ option :warn,
52
+ short: '-w N',
53
+ long: '--warn N',
54
+ description: 'Heap used in bytes WARNING threshold',
55
+ proc: proc(&:to_i),
56
+ default: 0
57
+
58
+ option :timeout,
59
+ description: 'Sets the connection timeout for REST client',
60
+ short: '-t SECS',
61
+ long: '--timeout SECS',
62
+ proc: proc(&:to_i),
63
+ default: 30
64
+
65
+ option :crit,
66
+ short: '-c N',
67
+ long: '--crit N',
68
+ description: 'Heap used in bytes CRITICAL threshold',
69
+ proc: proc(&:to_i),
70
+ default: 0
71
+
72
+ option :percentage,
73
+ short: '-P',
74
+ long: '--percentage',
75
+ description: 'Use the WARNING and CRITICAL threshold numbers as percentage indicators of the total heap available',
76
+ default: false
77
+
78
+ def acquire_es_version
79
+ info = acquire_es_resource('/')
80
+ info['version']['number']
81
+ end
82
+
83
+ def acquire_es_resource(resource)
84
+ r = RestClient::Resource.new("http://#{config[:host]}:#{config[:port]}/#{resource}", timeout: config[:timeout])
85
+ JSON.parse(r.get)
86
+ rescue Errno::ECONNREFUSED
87
+ warning 'Connection refused'
88
+ rescue RestClient::RequestTimeout
89
+ warning 'Connection timed out'
90
+ rescue JSON::ParserError
91
+ warning 'Elasticsearch API returned invalid JSON'
92
+ end
93
+
94
+ def acquire_heap_data(return_max = false)
95
+ if Gem::Version.new(acquire_es_version) >= Gem::Version.new('1.0.0')
96
+ stats = acquire_es_resource('_nodes/_local/stats?jvm=true')
97
+ node = stats['nodes'].keys.first
98
+ else
99
+ stats = acquire_es_resource('_cluster/nodes/_local/stats?jvm=true')
100
+ node = stats['nodes'].keys.first
101
+ end
102
+ begin
103
+ if return_max
104
+ return stats['nodes'][node]['jvm']['mem']['heap_used_in_bytes'], stats['nodes'][node]['jvm']['mem']['heap_max_in_bytes']
105
+ else
106
+ stats['nodes'][node]['jvm']['mem']['heap_used_in_bytes']
107
+ end
108
+ rescue
109
+ warning 'Failed to obtain heap used in bytes'
110
+ end
111
+ end
112
+
113
+ def run
114
+ if config[:percentage]
115
+ heap_used, heap_max = acquire_heap_data(true)
116
+ heap_used_ratio = ((100 * heap_used) / heap_max).to_i
117
+ message "Heap used in bytes #{heap_used} (#{heap_used_ratio}% full)"
118
+ if heap_used_ratio >= config[:crit]
119
+ critical
120
+ elsif heap_used_ratio >= config[:warn]
121
+ warning
122
+ else
123
+ ok
124
+ end
125
+ else
126
+ heap_used = acquire_heap_data(false)
127
+ message "Heap used in bytes #{heap_used}"
128
+ if heap_used >= config[:crit]
129
+ critical
130
+ elsif heap_used >= config[:warn]
131
+ warning
132
+ else
133
+ ok
134
+ end
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,110 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # es-cluster-metrics
4
+ #
5
+ # DESCRIPTION:
6
+ # This plugin uses the ES API to collect metrics, producing a JSON
7
+ # document which is outputted to STDOUT. An exit status of 0 indicates
8
+ # the plugin has successfully collected and produced.
9
+ #
10
+ # OUTPUT:
11
+ # metric data
12
+ #
13
+ # PLATFORMS:
14
+ # Linux
15
+ #
16
+ # DEPENDENCIES:
17
+ # gem: sensu-plugin
18
+ # gem: rest-client
19
+ # gem: json
20
+ #
21
+ # USAGE:
22
+ # #YELLOW
23
+ #
24
+ # NOTES:
25
+ #
26
+ # LICENSE:
27
+ # Copyright 2011 Sonian, Inc <chefs@sonian.net>
28
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
29
+ # for details.
30
+ #
31
+
32
+ require 'sensu-plugin/metric/cli'
33
+ require 'rest-client'
34
+ require 'json'
35
+
36
+ #
37
+ # ES Cluster Metrics
38
+ #
39
+ class ESClusterMetrics < Sensu::Plugin::Metric::CLI::Graphite
40
+ option :scheme,
41
+ description: 'Metric naming scheme, text to prepend to metric',
42
+ short: '-s SCHEME',
43
+ long: '--scheme SCHEME',
44
+ default: "#{Socket.gethostname}.elasticsearch.cluster"
45
+
46
+ option :host,
47
+ description: 'Elasticsearch host',
48
+ short: '-h HOST',
49
+ long: '--host HOST',
50
+ default: 'localhost'
51
+
52
+ option :port,
53
+ description: 'Elasticsearch port',
54
+ short: '-p PORT',
55
+ long: '--port PORT',
56
+ proc: proc(&:to_i),
57
+ default: 9200
58
+
59
+ option :timeout,
60
+ description: 'Sets the connection timeout for REST client',
61
+ short: '-t SECS',
62
+ long: '--timeout SECS',
63
+ proc: proc(&:to_i),
64
+ default: 30
65
+
66
+ def acquire_es_version
67
+ info = get_es_resource('/')
68
+ info['version']['number']
69
+ end
70
+
71
+ def get_es_resource(resource)
72
+ r = RestClient::Resource.new("http://#{config[:host]}:#{config[:port]}/#{resource}", timeout: config[:timeout])
73
+ JSON.parse(r.get)
74
+ rescue Errno::ECONNREFUSED
75
+ warning 'Connection refused'
76
+ rescue RestClient::RequestTimeout
77
+ warning 'Connection timed out'
78
+ end
79
+
80
+ def master?
81
+ state = get_es_resource('/_cluster/state?filter_routing_table=true&filter_metadata=true&filter_indices=true')
82
+ if Gem::Version.new(acquire_es_version) >= Gem::Version.new('1.0.0')
83
+ local = get_es_resource('/_nodes/_local')
84
+ else
85
+ local = get_es_resource('/_cluster/nodes/_local')
86
+ end
87
+ local['nodes'].keys.first == state['master_node']
88
+ end
89
+
90
+ def acquire_health
91
+ health = get_es_resource('/_cluster/health').reject { |k, _v| %w(cluster_name timed_out).include?(k) }
92
+ health['status'] = %w(red yellow green).index(health['status'])
93
+ health
94
+ end
95
+
96
+ def acquire_document_count
97
+ document_count = get_es_resource('/_count?q=*:*')
98
+ document_count['count']
99
+ end
100
+
101
+ def run
102
+ if master?
103
+ acquire_health.each do |k, v|
104
+ output(config[:scheme] + '.' + k, v)
105
+ end
106
+ output(config[:scheme] + '.document_count', acquire_document_count)
107
+ end
108
+ ok
109
+ end
110
+ end
@@ -0,0 +1,240 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # es-node-graphite
4
+ #
5
+ # DESCRIPTION:
6
+ # This check creates node metrics from the elasticsearch API
7
+ #
8
+ # OUTPUT:
9
+ # metric data
10
+ #
11
+ # PLATFORMS:
12
+ # Linux, Windows, BSD, Solaris, etc
13
+ #
14
+ # DEPENDENCIES:
15
+ # gem: sensu-plugin
16
+ # gem: rest-client
17
+ # gem: json
18
+ #
19
+ # USAGE:
20
+ # #YELLOW
21
+ #
22
+ # NOTES:
23
+ # 2014/04
24
+ # Modifid by Vincent Janelle @randomfrequency http://github.com/vjanelle
25
+ # Add more metrics, fix es 1.x URLs, translate graphite stats from
26
+ # names directly
27
+ #
28
+ # 2012/12 - Modified by Zach Dunn @SillySophist http://github.com/zadunn
29
+ # To add more metrics, and correct for new versins of ES. Tested on
30
+ # ES Version 0.19.8
31
+ #
32
+ # LICENSE:
33
+ # Copyright 2013 Vincent Janelle <randomfrequency@gmail.com>
34
+ # Copyright 2012 Sonian, Inc <chefs@sonian.net>
35
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
36
+ # for details.
37
+ #
38
+
39
+ require 'sensu-plugin/metric/cli'
40
+ require 'rest-client'
41
+ require 'json'
42
+
43
+ #
44
+ # ES Node Graphite Metrics
45
+ #
46
+ class ESNodeGraphiteMetrics < Sensu::Plugin::Metric::CLI::Graphite
47
+ option :scheme,
48
+ description: 'Metric naming scheme, text to prepend to queue_name.metric',
49
+ short: '-s SCHEME',
50
+ long: '--scheme SCHEME',
51
+ default: "#{Socket.gethostname}.elasticsearch"
52
+
53
+ option :server,
54
+ description: 'Elasticsearch server host.',
55
+ short: '-h HOST',
56
+ long: '--host HOST',
57
+ default: 'localhost'
58
+
59
+ option :port,
60
+ description: 'Elasticsearch port.',
61
+ short: '-p PORT',
62
+ long: '--port PORT',
63
+ proc: proc(&:to_i),
64
+ default: 9200
65
+
66
+ option :timeout,
67
+ description: 'Request timeout to elasticsearch',
68
+ short: '-t TIMEOUT',
69
+ long: '--timeout TIMEOUT',
70
+ proc: proc(&:to_i),
71
+ default: 30
72
+
73
+ option :disable_jvm_stats,
74
+ description: 'Disable JVM statistics',
75
+ long: '--disable-jvm-stats',
76
+ boolean: true,
77
+ default: false
78
+
79
+ option :disable_os_stats,
80
+ description: 'Disable OS Stats',
81
+ long: '--disable-os-stat',
82
+ boolean: true,
83
+ default: false
84
+
85
+ option :disable_process_stats,
86
+ description: 'Disable process statistics',
87
+ long: '--disable-process-stats',
88
+ boolean: true,
89
+ default: false
90
+
91
+ option :disable_thread_pool_stats,
92
+ description: 'Disable thread-pool statistics',
93
+ long: '--disable-thread-pool-stats',
94
+ boolean: true,
95
+ default: false
96
+
97
+ def get_es_resource(resource)
98
+ r = RestClient::Resource.new("http://#{config[:server]}:#{config[:port]}/#{resource}?pretty", timeout: config[:timeout])
99
+ JSON.parse(r.get)
100
+ rescue Errno::ECONNREFUSED
101
+ warning 'Connection refused'
102
+ rescue RestClient::RequestTimeout
103
+ warning 'Connection timed out'
104
+ end
105
+
106
+ def acquire_es_version
107
+ info = get_es_resource('/')
108
+ info['version']['number']
109
+ end
110
+
111
+ def run
112
+ # invert various stats depending on if some flags are set
113
+ os_stat = !config[:disable_os_stats]
114
+ process_stats = !config[:disable_process_stats]
115
+ jvm_stats = !config[:disable_jvm_stats]
116
+ tp_stats = !config[:disable_thread_pool_stats]
117
+
118
+ es_version = Gem::Version.new(acquire_es_version)
119
+
120
+ if es_version >= Gem::Version.new('1.0.0')
121
+ stats_query_array = %w(indices http network transport thread_pool)
122
+ stats_query_array.push('jvm') if jvm_stats == true
123
+ stats_query_array.push('os') if os_stat == true
124
+ stats_query_array.push('process') if process_stats == true
125
+ stats_query_array.push('tp_stats') if tp_stats == true
126
+ stats_query_string = stats_query_array.join(',')
127
+ else
128
+ stats_query_string = [
129
+ 'clear=true',
130
+ 'indices=true',
131
+ 'http=true',
132
+ "jvm=#{jvm_stats}",
133
+ 'network=true',
134
+ "os=#{os_stat}",
135
+ "process=#{process_stats}",
136
+ "thread_pool=#{tp_stats}",
137
+ 'transport=true',
138
+ 'thread_pool=true'
139
+ ].join('&')
140
+ end
141
+
142
+ if Gem::Version.new(acquire_es_version) >= Gem::Version.new('1.0.0')
143
+ stats = get_es_resource("_nodes/_local/stats?#{stats_query_string}")
144
+ else
145
+ stats = get_es_resource("_cluster/nodes/_local/stats?#{stats_query_string}")
146
+ end
147
+
148
+ timestamp = Time.now.to_i
149
+ node = stats['nodes'].values.first
150
+
151
+ metrics = {}
152
+
153
+ if os_stat
154
+ metrics['os.load_average'] = node['os']['load_average'][0]
155
+ metrics['os.load_average.1'] = node['os']['load_average'][0]
156
+ metrics['os.load_average.5'] = node['os']['load_average'][1]
157
+ metrics['os.load_average.15'] = node['os']['load_average'][2]
158
+ metrics['os.mem.free_in_bytes'] = node['os']['mem']['free_in_bytes']
159
+ # ... Process uptime in millis?
160
+ metrics['os.uptime'] = node['os']['uptime_in_millis']
161
+ end
162
+
163
+ if process_stats
164
+ metrics['process.mem.resident_in_bytes'] = node['process']['mem']['resident_in_bytes']
165
+ end
166
+
167
+ if jvm_stats
168
+ metrics['jvm.mem.heap_used_in_bytes'] = node['jvm']['mem']['heap_used_in_bytes']
169
+ metrics['jvm.mem.non_heap_used_in_bytes'] = node['jvm']['mem']['non_heap_used_in_bytes']
170
+ metrics['jvm.mem.max_heap_size_in_bytes'] = 0
171
+
172
+ node['jvm']['mem']['pools'].each do |k, v|
173
+ metrics["jvm.mem.#{k.gsub(' ', '_')}.max_in_bytes"] = v['max_in_bytes']
174
+ metrics['jvm.mem.max_heap_size_in_bytes'] += v['max_in_bytes']
175
+ end
176
+
177
+ # This makes absolutely no sense - not sure what it's trying to measure - @vjanelle
178
+ # metrics['jvm.gc.collection_time_in_millis'] = node['jvm']['gc']['collection_time_in_millis'] + \
179
+ # node['jvm']['mem']['pools']['CMS Old Gen']['max_in_bytes']
180
+
181
+ node['jvm']['gc']['collectors'].each do |gc, gc_value|
182
+ gc_value.each do |k, v|
183
+ # this contains stupid things like '28ms' and '2s', and there's already
184
+ # something that counts in millis, which makes more sense
185
+ unless k.end_with? 'collection_time'
186
+ metrics["jvm.gc.collectors.#{gc}.#{k}"] = v
187
+ end
188
+ end
189
+ end
190
+
191
+ metrics['jvm.threads.count'] = node['jvm']['threads']['count']
192
+ metrics['jvm.threads.peak_count'] = node['jvm']['threads']['peak_count']
193
+ end
194
+
195
+ node['indices'].each do |type, index|
196
+ index.each do |k, v|
197
+ # #YELLOW
198
+ unless k =~ /(_time|memory|size$)/ # rubocop:disable IfUnlessModifier
199
+ metrics["indices.#{type}.#{k}"] = v
200
+ end
201
+ end
202
+ end
203
+
204
+ node['transport'].each do |k, v|
205
+ # #YELLOW
206
+ unless k =~ /(_size$)/ # rubocop:disable IfUnlessModifier
207
+ metrics["transport.#{k}"] = v
208
+ end
209
+ end
210
+
211
+ metrics['http.current_open'] = node['http']['current_open']
212
+ metrics['http.total_opened'] = node['http']['total_opened']
213
+
214
+ metrics['network.tcp.active_opens'] = node['network']['tcp']['active_opens']
215
+ metrics['network.tcp.passive_opens'] = node['network']['tcp']['passive_opens']
216
+
217
+ metrics['network.tcp.in_segs'] = node['network']['tcp']['in_segs']
218
+ metrics['network.tcp.out_segs'] = node['network']['tcp']['out_segs']
219
+ metrics['network.tcp.retrans_segs'] = node['network']['tcp']['retrans_segs']
220
+ metrics['network.tcp.attempt_fails'] = node['network']['tcp']['attempt_fails']
221
+ metrics['network.tcp.in_errs'] = node['network']['tcp']['in_errs']
222
+ metrics['network.tcp.out_rsts'] = node['network']['tcp']['out_rsts']
223
+
224
+ metrics['network.tcp.curr_estab'] = node['network']['tcp']['curr_estab']
225
+ metrics['network.tcp.estab_resets'] = node['network']['tcp']['estab_resets']
226
+
227
+ if tp_stats
228
+ node['thread_pool'].each do |pool, stat|
229
+ stat.each do |k, v|
230
+ metrics["thread_pool.#{pool}.#{k}"] = v
231
+ end
232
+ end
233
+ end
234
+
235
+ metrics.each do |k, v|
236
+ output([config[:scheme], k].join('.'), v, timestamp)
237
+ end
238
+ ok
239
+ end
240
+ end
@@ -0,0 +1,79 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # es-node-metrics
4
+ #
5
+ # DESCRIPTION:
6
+ # This plugin uses the ES API to collect metrics, producing a JSON
7
+ # document which is outputted to STDOUT. An exit status of 0 indicates
8
+ # the plugin has successfully collected and produced.
9
+ #
10
+ # OUTPUT:
11
+ # metric data
12
+ #
13
+ # PLATFORMS:
14
+ # Linux
15
+ #
16
+ # DEPENDENCIES:
17
+ # gem: sensu-plugin
18
+ # gem: rest-client
19
+ # gem: json
20
+ #
21
+ # USAGE:
22
+ # #YELLOW
23
+ #
24
+ # NOTES:
25
+ #
26
+ # LICENSE:
27
+ # Copyright 2011 Sonian, Inc <chefs@sonian.net>
28
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
29
+ # for details.
30
+ #
31
+
32
+ require 'sensu-plugin/metric/cli'
33
+ require 'rest-client'
34
+ require 'json'
35
+
36
+ #
37
+ # ES Node Metrics
38
+ #
39
+ class ESMetrics < Sensu::Plugin::Metric::CLI::Graphite
40
+ option :scheme,
41
+ description: 'Metric naming scheme, text to prepend to queue_name.metric',
42
+ short: '-s SCHEME',
43
+ long: '--scheme SCHEME',
44
+ default: "#{Socket.gethostname}.elasticsearch"
45
+
46
+ option :host,
47
+ description: 'Elasticsearch server host.',
48
+ short: '-h HOST',
49
+ long: '--host HOST',
50
+ default: 'localhost'
51
+
52
+ option :port,
53
+ description: 'Elasticsearch port',
54
+ short: '-p PORT',
55
+ long: '--port PORT',
56
+ proc: proc(&:to_i),
57
+ default: 9200
58
+
59
+ def run
60
+ ln = RestClient::Resource.new "http://#{config[:host]}:#{config[:port]}/_cluster/nodes/_local", timeout: 30
61
+ stats = RestClient::Resource.new "http://#{config[:host]}:#{config[:port]}/_cluster/nodes/_local/stats", timeout: 30
62
+ ln = JSON.parse(ln.get)
63
+ stats = JSON.parse(stats.get)
64
+ timestamp = Time.now.to_i
65
+ node = stats['nodes'].values.first
66
+ node['jvm']['mem']['heap_max_in_bytes'] = ln['nodes'].values.first['jvm']['mem']['heap_max_in_bytes']
67
+ metrics = {}
68
+ metrics['os.load_average'] = node['os']['load_average'][0]
69
+ metrics['os.mem.free_in_bytes'] = node['os']['mem']['free_in_bytes']
70
+ metrics['process.mem.resident_in_bytes'] = node['process']['mem']['resident_in_bytes']
71
+ metrics['jvm.mem.heap_used_in_bytes'] = node['jvm']['mem']['heap_used_in_bytes']
72
+ metrics['jvm.mem.non_heap_used_in_bytes'] = node['jvm']['mem']['non_heap_used_in_bytes']
73
+ metrics['jvm.gc.collection_time_in_millis'] = node['jvm']['gc']['collection_time_in_millis']
74
+ metrics.each do |k, v|
75
+ output([config[:scheme], k].join('.'), v, timestamp)
76
+ end
77
+ ok
78
+ end
79
+ end
@@ -0,0 +1,7 @@
1
+ #
2
+ # Set gem version
3
+ #
4
+ module SensuPluginsElasticsearch
5
+ # Gem version
6
+ VERSION = '0.0.1.alpha.2'
7
+ end
data.tar.gz.sig ADDED
@@ -0,0 +1 @@
1
+ �q��1��[+r�lO�S�؃n }���?��A�IX�vh+�x��l8�^;<�~�d�U}��������o���v�1�����;ɔ�7#\�懐�����y� ��ǧ��e�/'E,b�����"g4_��O�� ��`c��R`���_"�@E�!�t �j%��Ir[��e0S0.6��n}zF� &���ndG��¸�1�A��ak#� ��x)���=
metadata ADDED
@@ -0,0 +1,249 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sensu-plugins-elasticsearch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.alpha.2
5
+ platform: ruby
6
+ authors:
7
+ - Yieldbot, Inc. and contributors
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDgDCCAmigAwIBAgIBATANBgkqhkiG9w0BAQUFADBDMRIwEAYDVQQDDAltYXR0
14
+ am9uZXMxGDAWBgoJkiaJk/IsZAEZFgh5aWVsZGJvdDETMBEGCgmSJomT8ixkARkW
15
+ A2NvbTAeFw0xNTAxMjgyMTAyNTFaFw0xNjAxMjgyMTAyNTFaMEMxEjAQBgNVBAMM
16
+ CW1hdHRqb25lczEYMBYGCgmSJomT8ixkARkWCHlpZWxkYm90MRMwEQYKCZImiZPy
17
+ LGQBGRYDY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyTSzVYnO
18
+ CLgyrIyT1mBQakArQyW8xhi6MlDqyzXHJGeERT790U6EgoBVeS4XoK0ptFZNR8Tf
19
+ zko0w+Nv47TarSCgkPOaxY+mxWnAVR10dOmfeLr7huiMyps+YD56/EF2FqQ3jf/+
20
+ qohENfKD91qy1ieEy+Fn7Pf74ltbNKUdkb9a9eFXQ0DQ4ip5vik7DzjQkUTj4lca
21
+ k6ArwnmHX4YDhZoYtrQJ8jVktN0/+NtA40M5qkCYHNe5tUW25b/tKVYuioxG6b2Z
22
+ oIzaZxRLxf6HVAWpCVRT/F5+/yjigkX4u++eYacfLGleXQzoK7BL65vHGMJygWEE
23
+ 0TKGqFOrl/L0AQIDAQABo38wfTAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNV
24
+ HQ4EFgQUEf6a8Td7MrSZc8ImbLFZAENPbz0wIQYDVR0RBBowGIEWbWF0dGpvbmVz
25
+ QHlpZWxkYm90LmNvbTAhBgNVHRIEGjAYgRZtYXR0am9uZXNAeWllbGRib3QuY29t
26
+ MA0GCSqGSIb3DQEBBQUAA4IBAQBbzXAYA3BVGw8DZ0YYoY1VHPNEcH5qPIApmHO8
27
+ rvSmuUT0yMEi7u00H/5uHRFf4LleGT/+sTdyXKsNPGT9kdRuQEgwi+vf7Zfvd8aX
28
+ UF/+4VkEYf/8rV8Ere6u2QaWPgApdMV6JjKr1fAwCTd8AuGXNaWItiPPMseSQzLJ
29
+ JKP4hVvbc1d+oS925B1lcBiqn2aYvElbyNAVmQPywNNqkWmvtlqj9ZVJfV5HQLdu
30
+ 8sHuVruarogxxKPBzlL2is4EUb6oN/RdpGx2l4254+nyR+abg//Ed27Ym0PkB4lk
31
+ HP0m8WSjZmFr109pE/sVsM5jtOCvogyujQOjNVGN4gz1wwPr
32
+ -----END CERTIFICATE-----
33
+ date: 2015-03-24 00:00:00.000000000 Z
34
+ dependencies:
35
+ - !ruby/object:Gem::Dependency
36
+ name: sensu-plugin
37
+ requirement: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '='
40
+ - !ruby/object:Gem::Version
41
+ version: 1.1.0
42
+ type: :runtime
43
+ prerelease: false
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '='
47
+ - !ruby/object:Gem::Version
48
+ version: 1.1.0
49
+ - !ruby/object:Gem::Dependency
50
+ name: json
51
+ requirement: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '='
54
+ - !ruby/object:Gem::Version
55
+ version: 1.8.2
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '='
61
+ - !ruby/object:Gem::Version
62
+ version: 1.8.2
63
+ - !ruby/object:Gem::Dependency
64
+ name: rest-client
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '='
68
+ - !ruby/object:Gem::Version
69
+ version: 1.8.0
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '='
75
+ - !ruby/object:Gem::Version
76
+ version: 1.8.0
77
+ - !ruby/object:Gem::Dependency
78
+ name: codeclimate-test-reporter
79
+ requirement: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ type: :development
85
+ prerelease: false
86
+ version_requirements: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ - !ruby/object:Gem::Dependency
92
+ name: rubocop
93
+ requirement: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '='
96
+ - !ruby/object:Gem::Version
97
+ version: 0.17.0
98
+ type: :development
99
+ prerelease: false
100
+ version_requirements: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '='
103
+ - !ruby/object:Gem::Version
104
+ version: 0.17.0
105
+ - !ruby/object:Gem::Dependency
106
+ name: rspec
107
+ requirement: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ~>
110
+ - !ruby/object:Gem::Version
111
+ version: '3.1'
112
+ type: :development
113
+ prerelease: false
114
+ version_requirements: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ~>
117
+ - !ruby/object:Gem::Version
118
+ version: '3.1'
119
+ - !ruby/object:Gem::Dependency
120
+ name: bundler
121
+ requirement: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: '1.7'
126
+ type: :development
127
+ prerelease: false
128
+ version_requirements: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ~>
131
+ - !ruby/object:Gem::Version
132
+ version: '1.7'
133
+ - !ruby/object:Gem::Dependency
134
+ name: rake
135
+ requirement: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ~>
138
+ - !ruby/object:Gem::Version
139
+ version: '10.0'
140
+ type: :development
141
+ prerelease: false
142
+ version_requirements: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ~>
145
+ - !ruby/object:Gem::Version
146
+ version: '10.0'
147
+ - !ruby/object:Gem::Dependency
148
+ name: github-markup
149
+ requirement: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ~>
152
+ - !ruby/object:Gem::Version
153
+ version: '1.3'
154
+ type: :development
155
+ prerelease: false
156
+ version_requirements: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ~>
159
+ - !ruby/object:Gem::Version
160
+ version: '1.3'
161
+ - !ruby/object:Gem::Dependency
162
+ name: redcarpet
163
+ requirement: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ~>
166
+ - !ruby/object:Gem::Version
167
+ version: '3.2'
168
+ type: :development
169
+ prerelease: false
170
+ version_requirements: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ~>
173
+ - !ruby/object:Gem::Version
174
+ version: '3.2'
175
+ - !ruby/object:Gem::Dependency
176
+ name: yard
177
+ requirement: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ~>
180
+ - !ruby/object:Gem::Version
181
+ version: '0.8'
182
+ type: :development
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ~>
187
+ - !ruby/object:Gem::Version
188
+ version: '0.8'
189
+ - !ruby/object:Gem::Dependency
190
+ name: pry
191
+ requirement: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - ~>
194
+ - !ruby/object:Gem::Version
195
+ version: '0.10'
196
+ type: :development
197
+ prerelease: false
198
+ version_requirements: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - ~>
201
+ - !ruby/object:Gem::Version
202
+ version: '0.10'
203
+ description: Sensu Plugins Elasticsearch checks
204
+ email: <sensu-users@googlegroups.com>
205
+ executables:
206
+ - check-es-cluster-status.rb
207
+ - check-es-file-descriptors.rb
208
+ - check-es-heap.rb
209
+ - metrics-es-cluster.rb
210
+ - metrics-es-node-graphite.rb
211
+ - metrics-es-node.rb
212
+ extensions: []
213
+ extra_rdoc_files: []
214
+ files:
215
+ - bin/check-es-cluster-status.rb
216
+ - bin/check-es-file-descriptors.rb
217
+ - bin/check-es-heap.rb
218
+ - bin/metrics-es-cluster.rb
219
+ - bin/metrics-es-node-graphite.rb
220
+ - bin/metrics-es-node.rb
221
+ - lib/sensu-plugins-elasticsearch.rb
222
+ - LICENSE
223
+ - README.md
224
+ - CHANGELOG.md
225
+ homepage: https://github.com/sensu-plugins/sensu-plugins-elasticsearch
226
+ licenses:
227
+ - MIT
228
+ metadata: {}
229
+ post_install_message:
230
+ rdoc_options: []
231
+ require_paths:
232
+ - lib
233
+ required_ruby_version: !ruby/object:Gem::Requirement
234
+ requirements:
235
+ - - '>='
236
+ - !ruby/object:Gem::Version
237
+ version: 1.9.3
238
+ required_rubygems_version: !ruby/object:Gem::Requirement
239
+ requirements:
240
+ - - '>'
241
+ - !ruby/object:Gem::Version
242
+ version: 1.3.1
243
+ requirements: []
244
+ rubyforge_project:
245
+ rubygems_version: 2.0.14
246
+ signing_key:
247
+ specification_version: 4
248
+ summary: Sensu Plugins Elasticsearch checks
249
+ test_files: []
metadata.gz.sig ADDED
@@ -0,0 +1,3 @@
1
+ �����^��O�Y�3���&H-F�'�F�@�M.-�Ph�U�N@e���=���0� �g)��g�EZ�푶^7j��Н4���A���(l�W3�s �[V^
2
+ ��0`&Db���3��Dke�g�`v�t��f�,�#+�
3
+ ����c��|0a�.-5��芆