sensu-plugins-zookeeper 1.2.0 → 1.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 174dd29207e5b80cb3b2eec532665c8c4ac8611c
4
- data.tar.gz: 859d3e6f1c0c2c33d7fe5e654fed03f573f53d58
3
+ metadata.gz: 72c0c089bdf151003b5f21a405e2fa917840ef76
4
+ data.tar.gz: d3a5f610c72fb9d9ef6c331eacd18b2e584d4898
5
5
  SHA512:
6
- metadata.gz: 0ec579d7d4d31b10c00dbb1db9d2e82f3b1806ae6e6e0c190943c01a600993731feaab4c01cb1b6d9b333f6d5549409c4800e397d7734a03bf233a0c274ab05f
7
- data.tar.gz: fd914498dfd52ef03f352ee7a119f6929e4fa776d5093ea97ae1d16ca369c26953f2e9145780d75c05c179c09c6f148115df340b769cccbeae7481a2a17989d1
6
+ metadata.gz: 7ef6c1fdb309c82f192b9299f07f4423e5f5efa518411ca14e3ac4ab02868a6523f46c06ce1a3f233696f9c282a84a5519e7a0be6e357b77564e6202e1f07715
7
+ data.tar.gz: 5816a75806675c37e4e155eb3dafbe80c3ea694769bd2b42460dd64cc09901f5fcf866d554e0b1808cd62175b15b2056b30a050208e110608aa99545c861a6cd
data/CHANGELOG.md CHANGED
@@ -1,10 +1,22 @@
1
1
  # Change Log
2
2
  This project adheres to [Semantic Versioning](http://semver.org/).
3
3
 
4
- This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
4
+ This CHANGELOG follows the format listed at [Our CHANGELOG Guidelines ](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md).
5
+ Which is based on [Keep A Changelog](http://keepachangelog.com/)
5
6
 
6
7
  ## [Unreleased]
7
8
 
9
+ ## [1.3.0] - 2017-09-09
10
+ ### Added
11
+ - metrics-zookeeper-cluster.rb: new script to gather metrics from a zookeeper cluster (@fsniper)
12
+
13
+ ### Changed
14
+ - metrics-zookeeper-cluster.rb: use the plugin name + version as the default user agent over some arbitrary version of curl (@majormoses)
15
+ - updated PR template and CHANGELOG with new CHANGELOG guideline location (@majormoses)
16
+
17
+ ### Fixed
18
+ - spelling in PR template (@majormoses)
19
+
8
20
  ## [1.2.0] - 2017-08-28
9
21
  ### Added
10
22
  - check-zookeper-cluster
@@ -48,7 +60,8 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
48
60
  ### Added
49
61
  - initial release
50
62
 
51
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-zookeeper/compare/1.1.0...HEAD
63
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-zookeeper/compare/1.3.0...HEAD
64
+ [1.3.0]: https://github.com/sensu-plugins/sensu-plugins-zookeeper/compare/1.2.0...1.3.0
52
65
  [1.2.0]: https://github.com/sensu-plugins/sensu-plugins-zookeeper/compare/1.1.0...1.2.0
53
66
  [1.1.0]: https://github.com/sensu-plugins/sensu-plugins-zookeeper/compare/1.0.0...1.1.0
54
67
  [1.0.0]: https://github.com/sensu-plugins/sensu-plugins-zookeeper/compare/0.1.0...1.0.0
data/README.md CHANGED
@@ -18,6 +18,7 @@
18
18
  * check-zookeeper-mode.rb - Check if Zookeeper node is in standalone or cluster(leader or follower) mode
19
19
  * check-zookeeper-cluster.rb - Check if a exhibitor managed Zookeeper cluster is OK.
20
20
  * metrics-zookeeper.rb - Gather metrics from Zookeeper
21
+ * metrics-zookeeper-cluster.rb - Gather metrics from An Exhibitor run Zookeeper cluster
21
22
 
22
23
  ## Usage
23
24
 
@@ -0,0 +1,201 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # metrics-zookeeper.rb
4
+ #
5
+ # Collect ZooKeeper metrics
6
+ # ===
7
+ #
8
+ # DESCRIPTION:
9
+ # This plugin gathers metrics from an Exhibitor run ZooKeeper cluster,
10
+ # based on the collectd plugin:
11
+ #
12
+ # https://github.com/Nextdoor/collectd_plugins/blob/master/zookeeper/zookeeper.sh
13
+ #
14
+ #
15
+ # PLATFORMS:
16
+ # Linux, BSD, Solaris
17
+ #
18
+ # DEPENDENCIES:
19
+ # gem: sensu-plugin
20
+ #
21
+ # LICENSE:
22
+ # Sean Clemmer sczizzo@gmail.com
23
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
24
+ # for details.
25
+ #
26
+
27
+ require 'sensu-plugin/metric/cli'
28
+ require 'socket'
29
+ require 'net/http'
30
+ require 'json'
31
+
32
+ class ZookeeperMetrics < Sensu::Plugin::Metric::CLI::Graphite
33
+ option :exhibitor,
34
+ description: 'exhibitor end node for status checks',
35
+ short: '-e Exhibitor status end point',
36
+ long: '--exhibitor status end point',
37
+ default: 'http://localhost/exhibitor/v1/cluster/status'
38
+
39
+ option :scheme,
40
+ description: 'Metric naming scheme, text to prepend to metrics',
41
+ long: '--scheme SCHEME',
42
+ default: 'zookeeper'
43
+
44
+ def follow_url(uri_str, agent = "sensu-plugins-zookeeper/#{SensuPluginsZookeeper::Version::VER_STRING}", max_attempts = 10, timeout = 10)
45
+ attempts = 0
46
+ cookie = nil
47
+
48
+ until attempts >= max_attempts
49
+ attempts += 1
50
+
51
+ url = URI.parse(uri_str)
52
+ http = Net::HTTP.new(url.host, url.port)
53
+ http.open_timeout = timeout
54
+ http.read_timeout = timeout
55
+ path = url.path
56
+ path = '/' if path == ''
57
+ path += '?' + url.query unless url.query.nil?
58
+
59
+ params = { 'User-Agent' => agent, 'Accept' => '*/*' }
60
+ params['Cookie'] = cookie unless cookie.nil?
61
+ request = Net::HTTP::Get.new(path, params)
62
+
63
+ if url.instance_of?(URI::HTTPS)
64
+ http.use_ssl = true
65
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
66
+ end
67
+ response = http.request(request)
68
+
69
+ case response
70
+ when Net::HTTPSuccess then
71
+ break
72
+ when Net::HTTPRedirection then
73
+ location = response['Location']
74
+ cookie = response['Set-Cookie']
75
+ new_uri = URI.parse(location)
76
+ uri_str = if new_uri.relative?
77
+ url + location
78
+ else
79
+ new_uri.to_s
80
+ end
81
+ else
82
+ raise 'Unexpected response: ' + response.inspect
83
+ end
84
+
85
+ end
86
+ raise 'Too many http redirects' if attempts == max_attempts
87
+
88
+ response
89
+ end
90
+
91
+ def dotted(*args)
92
+ args.join('.')
93
+ end
94
+
95
+ def zk_command(four_letter_word, host, port)
96
+ Socket.tcp(host, port) do |sock|
97
+ sock.print "#{four_letter_word}\r\n"
98
+ sock.close_write
99
+ sock.read
100
+ end
101
+ end
102
+
103
+ def exhibitor_status
104
+ response = follow_url(config[:exhibitor])
105
+ JSON.parse(response.body)
106
+ rescue StandardError => e
107
+ [false, json, ['exhibitor status is not http 200 ' + e.message]]
108
+ end
109
+
110
+ def run
111
+ timestamp = Time.now.to_i
112
+
113
+ json = exhibitor_status
114
+ json.each do |zk|
115
+ hostname = zk['hostname']
116
+ response = zk_command(:mntr, hostname, 2181)
117
+ metrics = {}
118
+
119
+ if response =~ /^zk_avg_latency\s*(\d+)$/
120
+ metrics[:zk_avg_latency] = Regexp.last_match(1).to_i
121
+ end
122
+
123
+ if response =~ /^zk_max_latency\s*(\d+)$/
124
+ metrics[:zk_max_latency] = Regexp.last_match(1).to_i
125
+ end
126
+
127
+ if response =~ /^zk_min_latency\s*(\d+)$/
128
+ metrics[:zk_min_latency] = Regexp.last_match(1).to_i
129
+ end
130
+
131
+ if response =~ /^zk_packets_received\s*(\d+)$/
132
+ metrics[:zk_packets_received] = Regexp.last_match(1).to_i
133
+ end
134
+
135
+ if response =~ /^zk_packets_sent\s*(\d+)$/
136
+ metrics[:zk_packets_sent] = Regexp.last_match(1).to_i
137
+ end
138
+
139
+ if response =~ /^zk_num_alive_connections\s*(\d+)$/
140
+ metrics[:zk_num_alive_connections] = Regexp.last_match(1).to_i
141
+ end
142
+
143
+ if response =~ /^zk_outstanding_requests\s*(\d+)$/
144
+ metrics[:zk_outstanding_requests] = Regexp.last_match(1).to_i
145
+ end
146
+
147
+ metrics[:zk_is_leader] = if response =~ /^zk_server_state\s*leader$/
148
+ 1
149
+ else
150
+ 0
151
+ end
152
+
153
+ if response =~ /^zk_znode_count\s*(\d+)$/
154
+ metrics[:zk_znode_count] = Regexp.last_match(1).to_i
155
+ end
156
+
157
+ if response =~ /^zk_watch_count\s*(\d+)$/
158
+ metrics[:zk_watch_count] = Regexp.last_match(1).to_i
159
+ end
160
+
161
+ if response =~ /^zk_ephemerals_count\s*(\d+)$/
162
+ metrics[:zk_ephemerals_count] = Regexp.last_match(1).to_i
163
+ end
164
+
165
+ if response =~ /^zk_approximate_data_size\s*(\d+)$/
166
+ metrics[:zk_approximate_data_size] = Regexp.last_match(1).to_i
167
+ end
168
+
169
+ if response =~ /^zk_open_file_descriptor_count\s*(\d+)$/
170
+ metrics[:zk_open_file_descriptor_count] = Regexp.last_match(1).to_i
171
+ end
172
+
173
+ if response =~ /^zk_max_file_descriptor_count\s*(\d+)$/
174
+ metrics[:zk_max_file_descriptor_count] = Regexp.last_match(1).to_i
175
+ end
176
+
177
+ metrics[:zk_followers] = if response =~ /^zk_followers\s*(\d+)$/
178
+ Regexp.last_match(1).to_i
179
+ else
180
+ 0
181
+ end
182
+
183
+ metrics[:zk_synced_followers] = if response =~ /^zk_synced_followers\s*(\d+)$/
184
+ Regexp.last_match(1).to_i
185
+ else
186
+ 0
187
+ end
188
+
189
+ metrics[:zk_pending_syncs] = if response =~ /^zk_pending_syncs\s*(\d+)$/
190
+ Regexp.last_match(1).to_i
191
+ else
192
+ 0
193
+ end
194
+
195
+ metrics.each do |metric, value|
196
+ output dotted(config[:scheme], hostname, metric), value, timestamp
197
+ end
198
+ end
199
+ ok
200
+ end
201
+ end
@@ -1,7 +1,7 @@
1
1
  module SensuPluginsZookeeper
2
2
  module Version
3
3
  MAJOR = 1
4
- MINOR = 2
4
+ MINOR = 3
5
5
  PATCH = 0
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-zookeeper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sensu Plugins and contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-29 00:00:00.000000000 Z
11
+ date: 2017-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sensu-plugin
@@ -174,6 +174,7 @@ executables:
174
174
  - check-zookeeper-mode.rb
175
175
  - check-zookeeper-reqs.rb
176
176
  - check-zookeeper-ruok.rb
177
+ - metrics-zookeeper-cluster.rb
177
178
  - metrics-zookeeper.rb
178
179
  extensions: []
179
180
  extra_rdoc_files: []
@@ -188,6 +189,7 @@ files:
188
189
  - bin/check-zookeeper-mode.rb
189
190
  - bin/check-zookeeper-reqs.rb
190
191
  - bin/check-zookeeper-ruok.rb
192
+ - bin/metrics-zookeeper-cluster.rb
191
193
  - bin/metrics-zookeeper.rb
192
194
  - lib/sensu-plugins-zookeeper.rb
193
195
  - lib/sensu-plugins-zookeeper/version.rb
@@ -215,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
217
  version: '0'
216
218
  requirements: []
217
219
  rubyforge_project:
218
- rubygems_version: 2.4.5
220
+ rubygems_version: 2.6.13
219
221
  signing_key:
220
222
  specification_version: 4
221
223
  summary: Sensu plugins for zookeeper