sensu-plugins-kafka 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/CHANGELOG.md +21 -2
- data/README.md +2 -0
- data/bin/check-topic.rb +57 -0
- data/lib/sensu-plugins-kafka/version.rb +2 -2
- metadata +18 -4
- data/bin/check-topics.rb +0 -92
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1b799c7bf8d17a7870c97275bb99b07407570a8
|
4
|
+
data.tar.gz: b7b104f9ff24fef9fd427d5181b2aed90076cdd0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2ea96c76830fbe78f8941219bf5bff01430a57513157dabed2b50f9c25dc58802cf8f02f5415e7db88e202399d5df3b70e2e12820543f63aa05606a4be93955
|
7
|
+
data.tar.gz: 7788b54b1238ce65d43928175a9675a4b35fa0bb9306eae4e1bd2a964586e271f0cfc2f2bfda4caccce14be5e598678258a72037f4e029359452ed3f08b03dba
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,25 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
3
3
|
|
4
4
|
This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
|
5
5
|
|
6
|
-
## Unreleased
|
6
|
+
## [Unreleased]
|
7
|
+
|
8
|
+
### Breaking Changes
|
9
|
+
### Added
|
10
|
+
### Fixed
|
11
|
+
### Changed
|
12
|
+
|
13
|
+
## [0.2.0] - 2017-02-09
|
14
|
+
|
15
|
+
### Breaking Changes
|
16
|
+
- check-topics.rb has been removed
|
17
|
+
|
7
18
|
### Added
|
8
|
-
-
|
19
|
+
- Add check-topic.rb
|
20
|
+
|
21
|
+
## [0.1.1] - 2017-02-04
|
22
|
+
|
23
|
+
### Fixed
|
24
|
+
- Ruby doc
|
25
|
+
|
26
|
+
## [0.1.0] - 2017-02-04
|
27
|
+
- First release
|
data/README.md
CHANGED
data/bin/check-topic.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-topic
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# This plugin checks topic properties.
|
7
|
+
#
|
8
|
+
# OUTPUT:
|
9
|
+
# plain-text
|
10
|
+
#
|
11
|
+
# PLATFORMS:
|
12
|
+
# Linux
|
13
|
+
#
|
14
|
+
# DEPENDENCIES:
|
15
|
+
# gem: sensu-plugin
|
16
|
+
# gem: zookeeper
|
17
|
+
#
|
18
|
+
# USAGE:
|
19
|
+
# ./check-topic
|
20
|
+
#
|
21
|
+
# NOTES:
|
22
|
+
#
|
23
|
+
# LICENSE:
|
24
|
+
# Olivier Bazoud
|
25
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
26
|
+
# for details.
|
27
|
+
#
|
28
|
+
|
29
|
+
require 'sensu-plugin/check/cli'
|
30
|
+
require 'json'
|
31
|
+
require 'zookeeper'
|
32
|
+
|
33
|
+
class TopicsCheck < Sensu::Plugin::Check::CLI
|
34
|
+
option :zookeeper,
|
35
|
+
description: 'ZooKeeper connect string (host:port,..)',
|
36
|
+
short: '-z ZOOKEEPER',
|
37
|
+
long: '--zookeeper ZOOKEEPER',
|
38
|
+
default: 'localhost:2181'
|
39
|
+
|
40
|
+
option :name,
|
41
|
+
description: 'Topic name',
|
42
|
+
short: '-n TOPIC_NAME',
|
43
|
+
long: '--name TOPIC_NAME'
|
44
|
+
|
45
|
+
def run
|
46
|
+
z = Zookeeper.new(config[:zookeeper])
|
47
|
+
|
48
|
+
live_topics = z.get_children(path: '/brokers/topics')[:children].sort
|
49
|
+
|
50
|
+
critical "#{topic[:name]} not found" unless live_topics.include? topic[:name]
|
51
|
+
|
52
|
+
ok
|
53
|
+
rescue => e
|
54
|
+
puts "Error: #{e.backtrace}"
|
55
|
+
critical "Error: #{e}"
|
56
|
+
end
|
57
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-plugins-kafka
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sensu-Plugins and contributors
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain:
|
11
11
|
- certs/sensu-plugins.pem
|
12
|
-
date: 2017-02-
|
12
|
+
date: 2017-02-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sensu-plugin
|
@@ -25,6 +25,20 @@ dependencies:
|
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '1.3'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: zookeeper
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.4.11
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 1.4.11
|
28
42
|
- !ruby/object:Gem::Dependency
|
29
43
|
name: codeclimate-test-reporter
|
30
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -155,7 +169,7 @@ description: Sensu plugins for Kafka
|
|
155
169
|
email: "<sensu-users@googlegroups.com>"
|
156
170
|
executables:
|
157
171
|
- check-consumer-lag.rb
|
158
|
-
- check-
|
172
|
+
- check-topic.rb
|
159
173
|
- metrics-consumer.rb
|
160
174
|
extensions: []
|
161
175
|
extra_rdoc_files: []
|
@@ -164,7 +178,7 @@ files:
|
|
164
178
|
- LICENSE
|
165
179
|
- README.md
|
166
180
|
- bin/check-consumer-lag.rb
|
167
|
-
- bin/check-
|
181
|
+
- bin/check-topic.rb
|
168
182
|
- bin/metrics-consumer.rb
|
169
183
|
- lib/sensu-plugins-kafka.rb
|
170
184
|
- lib/sensu-plugins-kafka/version.rb
|
data/bin/check-topics.rb
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
#! /usr/bin/env ruby
|
2
|
-
#
|
3
|
-
# check-topics
|
4
|
-
#
|
5
|
-
# DESCRIPTION:
|
6
|
-
# This plugin checks topics properties.
|
7
|
-
#
|
8
|
-
# OUTPUT:
|
9
|
-
# plain-text
|
10
|
-
#
|
11
|
-
# PLATFORMS:
|
12
|
-
# Linux
|
13
|
-
#
|
14
|
-
# DEPENDENCIES:
|
15
|
-
# gem: sensu-plugin
|
16
|
-
#
|
17
|
-
# USAGE:
|
18
|
-
# ./check-consumer-lag
|
19
|
-
#
|
20
|
-
# NOTES:
|
21
|
-
#
|
22
|
-
# LICENSE:
|
23
|
-
# Olivier Bazoud
|
24
|
-
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
25
|
-
# for details.
|
26
|
-
#
|
27
|
-
|
28
|
-
require 'sensu-plugin/check/cli'
|
29
|
-
|
30
|
-
class TopicCheck < Sensu::Plugin::Check::CLI
|
31
|
-
option :kafka_home,
|
32
|
-
description: 'Kafka home',
|
33
|
-
short: '-k NAME',
|
34
|
-
long: '--kafka-home NAME',
|
35
|
-
default: '/opt/kafka'
|
36
|
-
|
37
|
-
option :zookeeper,
|
38
|
-
description: 'ZooKeeper connect string',
|
39
|
-
short: '-z NAME',
|
40
|
-
long: '--zookeeper NAME',
|
41
|
-
default: 'localhost:2181'
|
42
|
-
|
43
|
-
option :properites,
|
44
|
-
description: 'Replication factor for this topic',
|
45
|
-
short: '-R N',
|
46
|
-
long: '--replication-factor N'
|
47
|
-
|
48
|
-
# read the output of a command
|
49
|
-
# @param cmd [String] the command to read the output from
|
50
|
-
def read_lines(cmd)
|
51
|
-
IO.popen(cmd + ' 2>&1') do |child|
|
52
|
-
child.read.split("\n")
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
# create a hash from the output of each line of a command
|
57
|
-
# @param line [String]
|
58
|
-
# @param cols
|
59
|
-
def line_to_hash(line, *cols)
|
60
|
-
Hash[cols.zip(line.strip.split(/\s+/, cols.size))]
|
61
|
-
end
|
62
|
-
|
63
|
-
# run command and return a hash from the output
|
64
|
-
# @param cmd [String]
|
65
|
-
def run_cmd(cmd)
|
66
|
-
read_lines(cmd).drop(1).map do |line|
|
67
|
-
line_to_hash(line, :_, :topic, :_, :partition, :_, :leader, :_, :replicas, :_, :isr)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def run
|
72
|
-
kafka_topics = "#{config[:kafka_home]}/bin/kafka-topics.sh"
|
73
|
-
unknown "Can not find #{kafka_topics}" unless File.exist?(kafka_topics)
|
74
|
-
|
75
|
-
cmd_details = "#{kafka_topics} --describe --zookeeper #{config[:zookeeper]} | grep -v ReplicationFactor"
|
76
|
-
results = run_cmd(cmd_details)
|
77
|
-
|
78
|
-
topics = results.group_by { |h| h[:topic] }
|
79
|
-
|
80
|
-
# {:_=>"Isr:", :topic=>"__consumer_offsets", :partition=>"49", :leader=>"172314554", :replicas=>"172314554,172314557,172314558", :isr=>"172314554,172314557,172314558"}
|
81
|
-
|
82
|
-
topics.each do |_, topic|
|
83
|
-
topic.inject(0) { |a, e| [a, e[:replicas].length].max }
|
84
|
-
end
|
85
|
-
ok
|
86
|
-
|
87
|
-
rescue => e
|
88
|
-
puts "Error: #{e}"
|
89
|
-
puts "Error: #{e.backtrace}"
|
90
|
-
critical "Error: #{e}"
|
91
|
-
end
|
92
|
-
end
|