sensu-plugins-zookeeper 1.1.0 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 326e3e7e050ee97c7391843215f8222618cc3584
4
- data.tar.gz: 3a8925749d5d0f87d6b14020b7ebca4608ef87c3
3
+ metadata.gz: 174dd29207e5b80cb3b2eec532665c8c4ac8611c
4
+ data.tar.gz: 859d3e6f1c0c2c33d7fe5e654fed03f573f53d58
5
5
  SHA512:
6
- metadata.gz: f2db1a9a3a1315978de601fdffd92b2c4c52821a3a6be7795b9a02de02a5a08e76ee1bfcc3de5b119bf3f7789aa74a7e305fef99f9ccc069a7289f62a119421d
7
- data.tar.gz: bfd3614b461395f46a35163c062394f0ea0926f1b6d544d02cc8a3753b9605f3b50886cd46532af1e189584488e8e4d592121f5064c5ad52cb2b319f38922a18
6
+ metadata.gz: 0ec579d7d4d31b10c00dbb1db9d2e82f3b1806ae6e6e0c190943c01a600993731feaab4c01cb1b6d9b333f6d5549409c4800e397d7734a03bf233a0c274ab05f
7
+ data.tar.gz: fd914498dfd52ef03f352ee7a119f6929e4fa776d5093ea97ae1d16ca369c26953f2e9145780d75c05c179c09c6f148115df340b769cccbeae7481a2a17989d1
data/CHANGELOG.md CHANGED
@@ -5,6 +5,11 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [1.2.0] - 2017-08-28
9
+ ### Added
10
+ - check-zookeper-cluster
11
+ - Ruby 2.4.1 testing
12
+
8
13
  ## [1.1.0] - 2017-03-23
9
14
  - add `check-zookeeper-mode` to check if zookeeper is in the expected mode (@karthik-altiscale)
10
15
 
@@ -44,6 +49,7 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
44
49
  - initial release
45
50
 
46
51
  [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-zookeeper/compare/1.1.0...HEAD
52
+ [1.2.0]: https://github.com/sensu-plugins/sensu-plugins-zookeeper/compare/1.1.0...1.2.0
47
53
  [1.1.0]: https://github.com/sensu-plugins/sensu-plugins-zookeeper/compare/1.0.0...1.1.0
48
54
  [1.0.0]: https://github.com/sensu-plugins/sensu-plugins-zookeeper/compare/0.1.0...1.0.0
49
55
  [0.1.0]: https://github.com/sensu-plugins/sensu-plugins-zookeeper/compare/0.0.4...0.1.0
data/README.md CHANGED
@@ -16,6 +16,7 @@
16
16
  * check-zookeeper-reqs.rb - Check if Zookeeper node has reliable number of outstanding requests
17
17
  * check-zookeeper-ruok.rb - Check if Zookeeper node responds to 'ruok' query succesfully
18
18
  * check-zookeeper-mode.rb - Check if Zookeeper node is in standalone or cluster(leader or follower) mode
19
+ * check-zookeeper-cluster.rb - Check if a exhibitor managed Zookeeper cluster is OK.
19
20
  * metrics-zookeeper.rb - Gather metrics from Zookeeper
20
21
 
21
22
  ## Usage
@@ -0,0 +1,169 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ #
4
+ # check-zookeeper-cluster
5
+ #
6
+ # DESCRIPTION:
7
+ # Check if a exhibitor managed Zookeeper cluster is OK.
8
+ #
9
+ # This check will get exhibitor status information,
10
+ # and check each seperate node for ruok.
11
+ # This check also will compare cluster node count with a spesific value,
12
+ # avg latency from mntr for a threshold value, and If the cluster
13
+ # has a leader.
14
+ #
15
+ # PLATFORMS:
16
+ # All
17
+ #
18
+ # DEPENDENCIES:
19
+ # gem: sensu-plugin
20
+ #
21
+ # USAGE:
22
+ # Check if a node has Zookeeper running and responds with imok.
23
+ #
24
+ # Cluster should have 3 nodes, exhibitor status endpoint is not default, and average latency threshold should be 10
25
+ # ./check-zookeeeper-cluster.rb -c 3 -e http://localhost:8181/exhibitor/v1/cluster/status -l 10
26
+ #
27
+
28
+ require 'sensu-plugin/check/cli'
29
+ require 'socket'
30
+ require 'net/http'
31
+ require 'json'
32
+
33
+ class CheckZookeeperCluster < Sensu::Plugin::Check::CLI
34
+ option :count,
35
+ description: 'Zookeeper cluster node count',
36
+ short: '-c count',
37
+ long: '--count count',
38
+ default: 3,
39
+ proc: proc(&:to_i)
40
+
41
+ option :zk_port,
42
+ description: 'Zookeeper nodes\' listen port',
43
+ short: '-p port',
44
+ long: '--port port',
45
+ default: 2181,
46
+ proc: proc(&:to_i)
47
+
48
+ option :count,
49
+ description: 'Zookeeper cluster node count',
50
+ short: '-c count',
51
+ long: '--count count',
52
+ default: 3,
53
+ proc: proc(&:to_i)
54
+
55
+ option :exhibitor,
56
+ description: 'exhibitor end node for status checks',
57
+ short: '-e Exhibitor status end point',
58
+ long: '--exhibitor status end point',
59
+ default: 'http://localhost/exhibitor/v1/cluster/status'
60
+
61
+ option :latency,
62
+ description: 'Critical threshold for Zookeeper average latency',
63
+ short: '-l TICKS',
64
+ long: '--latency TICKS',
65
+ proc: proc(&:to_i),
66
+ default: 10
67
+
68
+ option :timeout,
69
+ description: 'How long to wait for a reply in seconds.',
70
+ short: '-t SECS',
71
+ long: '--timeout SECS',
72
+ proc: proc(&:to_i),
73
+ default: 5
74
+
75
+ def zookeeper_latency(server, port)
76
+ l = 0
77
+ TCPSocket.open(server, port) do |socket|
78
+ socket.write 'mntr'
79
+ ready = IO.select([socket], nil, nil, config[:timeout])
80
+ if ready.nil?
81
+ critical %(Zookeeper did not respond to 'mntr' within #{config[:timeout]} seconds)
82
+ end
83
+ l = ready.first.first.read.chomp.split("\n")[1].split("\t")[1].to_i
84
+ end
85
+ end
86
+
87
+ def check_ruok(server, port)
88
+ result = false
89
+ TCPSocket.open(server, port) do |socket|
90
+ socket.write 'ruok'
91
+ ready = IO.select([socket], nil, nil, config[:timeout])
92
+
93
+ if ready.nil?
94
+ critical %(Zookeeper did not respond to 'ruok' within #{config[:timeout]} seconds)
95
+ end
96
+
97
+ result = ready.first.first.read.chomp
98
+ end
99
+ result == 'imok'
100
+ end
101
+
102
+ def _leader_count(json)
103
+ l_count = max_latency = 0
104
+ json.each do |zk|
105
+ l_count += 1 if zk['isLeader']
106
+ l = zookeeper_latency(zk['hostname'], config[:zk_port])
107
+ max_latency = [max_latency, l].max
108
+ end
109
+ [l_count, max_latency]
110
+ end
111
+
112
+ def _check_leader(json)
113
+ e = []
114
+ l_count, max_latency = _leader_count(json)
115
+ unless l_count == 1
116
+ e.push("cluster should have a leader (#{l_count})")
117
+ end
118
+ if max_latency > config[:latency]
119
+ e.push("cluster should have a lower latecy #{max_latency}")
120
+ end
121
+ return [true, e] if l_count == 1 && max_latency < config[:latency]
122
+ [false, e]
123
+ end
124
+
125
+ def check_exhibitor_endpoint(response)
126
+ json = JSON.parse(response.body)
127
+ e = []
128
+ r = false
129
+ if json.length == config[:count]
130
+ r, e = _check_leader(json)
131
+ else
132
+ e = ["cluster size mismatch (#{json.length}!=#{config[:count]})"]
133
+ end
134
+ [r, json, e]
135
+ end
136
+
137
+ def check_exhibitor
138
+ response = ''
139
+ json = ''
140
+ url = URI.parse(config[:exhibitor])
141
+ req = Net::HTTP::Get.new(url.path)
142
+ Net::HTTP.new(url.host, url.port).start do |http|
143
+ response = http.request(req)
144
+ end
145
+ return [false, json, ['exhibitor status is not http 200']] unless
146
+ response.is_a? Net::HTTPSuccess
147
+ r, json, e = check_exhibitor_endpoint(response)
148
+ [r, json, e]
149
+ end
150
+
151
+ def check_each_zk(json)
152
+ r = true
153
+ hosts = []
154
+ json.each do |zk|
155
+ r = check_ruok(zk['hostname'], config[:zk_port])
156
+ hosts.push(zk['hostname'])
157
+ return [false, ["#{zk['hostname']} is not ok"]] unless r
158
+ end
159
+ [true, hosts]
160
+ end
161
+
162
+ def run
163
+ result, json, errors = check_exhibitor
164
+ result, errors = check_each_zk(json) if result
165
+ message errors.join(', ')
166
+ ok if result
167
+ critical
168
+ end
169
+ end
@@ -1,7 +1,7 @@
1
1
  module SensuPluginsZookeeper
2
2
  module Version
3
3
  MAJOR = 1
4
- MINOR = 1
4
+ MINOR = 2
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.1.0
4
+ version: 1.2.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-03-24 00:00:00.000000000 Z
11
+ date: 2017-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sensu-plugin
@@ -168,6 +168,7 @@ description: Zookeeper plugins for checks and metrics
168
168
  email: "<sensu-users@googlegroups.com>"
169
169
  executables:
170
170
  - check-znode.rb
171
+ - check-zookeeper-cluster.rb
171
172
  - check-zookeeper-file-descriptors.rb
172
173
  - check-zookeeper-latency.rb
173
174
  - check-zookeeper-mode.rb
@@ -181,6 +182,7 @@ files:
181
182
  - LICENSE
182
183
  - README.md
183
184
  - bin/check-znode.rb
185
+ - bin/check-zookeeper-cluster.rb
184
186
  - bin/check-zookeeper-file-descriptors.rb
185
187
  - bin/check-zookeeper-latency.rb
186
188
  - bin/check-zookeeper-mode.rb