sensu-plugins-kafka 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 238d5d13127c16a53fd30c5a4dae4a05471547cf
4
- data.tar.gz: 0d81d88567c829276fb5a9a11db4c9eae162f196
3
+ metadata.gz: 0a503a49eba3fdde83ea058f05aa528e880e88d3
4
+ data.tar.gz: 987863996d1810bb470709f75141a9f6e5c6d752
5
5
  SHA512:
6
- metadata.gz: 41831c5fc35254acbf40b9cee04c8bf0735a9be6062f2a94f94b9552d8f85cd6fcfaa5356147ac369d7452965d7c1cba3c9a9dc2ea9478ee083a837f16cccc9c
7
- data.tar.gz: 2eb96ee56a1888894765e8d28614bd185919a1542abd5ae028092506afc86b018cca1909041d3ac28dfbfd7a44d486f6563125f2a4d6b15878361e507cf11ae6
6
+ metadata.gz: b48c13220791bec9f7d77e9502865bb208c91cc1767fb70788baa13a4329d05bb17449979ab76c39ded7e5f92666900945c86d59e04cd0e1927f0315d921aabc
7
+ data.tar.gz: 04d858babaebd2080e08adc7e0d34a879a384ea3899bea6b6e1c8e374e5dda15340df03606d7575da410342dc61325fa8e8b8d6df5673c73d1294a2a89a9de2d
data/CHANGELOG.md CHANGED
@@ -10,17 +10,22 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
10
10
  ### Fixed
11
11
  ### Changed
12
12
 
13
- ## [0.8.1]
13
+ ## [0.9.0] - 2017-02-16
14
+
15
+ ### Breaking Changes
16
+ - Refactoring metrics-consumer-lag to remove shell/jvm execution
17
+
18
+ ## [0.8.1] - 2017-02-16
14
19
 
15
20
  ### Fixed
16
21
  - check-consumer-lag: remove celluloid (temporary), fix data structure, fix partition_owner function
17
22
 
18
- ## [0.8.0]
23
+ ## [0.8.0] - 2017-02-15
19
24
 
20
25
  ### Breaking Changes
21
26
  - Refactoring check-consumer-lag to remove shell/jvm execution
22
27
 
23
- ## [0.7.0]
28
+ ## [0.7.0] - 2017-02-10
24
29
 
25
30
  ### Added
26
31
  - Add option to check topic's replicas
data/README.md CHANGED
@@ -20,8 +20,8 @@
20
20
 
21
21
  [Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
22
22
 
23
- Kafka installation is required where checks will be made.
24
-
25
- Kafka version: 0.8.2.x
23
+ Tested on:
24
+ * Zookeeper version: 3.4.6
25
+ * Kafka version: 0.8.2.x
26
26
 
27
27
  Note: In addition to the standard installation requirements the installation of this gem will require compiling the nokogiri gem. Due to this you'll need certain developmemnt packages on your system. On Ubuntu systems install build-essential, libxml2-dev and zlib1g-dev. On CentOS install gcc and zlib-devel.
@@ -26,6 +26,10 @@
26
26
 
27
27
  require 'sensu-plugin/metric/cli'
28
28
 
29
+ require 'json'
30
+ require 'poseidon'
31
+ require 'zookeeper'
32
+
29
33
  class ConsumerOffsetMetrics < Sensu::Plugin::Metric::CLI::Graphite
30
34
  option :scheme,
31
35
  description: 'Metric naming scheme, text to prepend to metric',
@@ -39,12 +43,6 @@ class ConsumerOffsetMetrics < Sensu::Plugin::Metric::CLI::Graphite
39
43
  long: '--group NAME',
40
44
  required: true
41
45
 
42
- option :kafka_home,
43
- description: 'Kafka home',
44
- short: '-k NAME',
45
- long: '--kafka-home NAME',
46
- default: '/opt/kafka'
47
-
48
46
  option :topic,
49
47
  description: 'Comma-separated list of consumer topics',
50
48
  short: '-t NAME',
@@ -62,51 +60,46 @@ class ConsumerOffsetMetrics < Sensu::Plugin::Metric::CLI::Graphite
62
60
  long: '--zookeeper NAME',
63
61
  default: 'localhost:2181'
64
62
 
65
- # read the output of a command
66
- # @param cmd [String] the command to read the output from
67
- def read_lines(cmd)
68
- IO.popen(cmd + ' 2>&1') do |child|
69
- child.read.split("\n")
70
- end
71
- end
63
+ def run
64
+ z = Zookeeper.new(config[:zookeeper])
72
65
 
73
- # create a hash from the output of each line of a command
74
- # @param line [String]
75
- # @param cols
76
- def line_to_hash(line, *cols)
77
- Hash[cols.zip(line.strip.split(/\s+/, cols.size))]
78
- end
66
+ group = config[:group]
67
+ topics = kafka_topics(z, group)
68
+
69
+ critical 'Could not found topics' if topics.empty?
70
+
71
+ consumers = {}
72
+ topics.each do |topic|
73
+ consumers[topic] = []
74
+
75
+ topics_partitions(z, topic).each do |partition|
76
+ leader = leader_broker(z, topic, partition)
77
+ consumer = Poseidon::PartitionConsumer.new('CheckConsumerLag', leader['host'], leader['port'], topic, partition, :latest_offset)
78
+ logsize = consumer.next_offset
79
79
 
80
- # run command and return a hash from the output
81
- # @param cmd [String]
82
- def run_cmd(cmd)
83
- read_lines(cmd).drop(1).map do |line|
84
- line_to_hash(line, :group, :topic, :pid, :offset, :logsize, :lag, :owner)
80
+ offset = consumer_offset(z, group, topic, partition)
81
+
82
+ lag = logsize - offset
83
+ consumers[topic].push(partition: partition, logsize: logsize, offset: offset, lag: lag)
84
+ end
85
85
  end
86
- end
87
86
 
88
- def run
89
- begin
90
- kafka_run_class = "#{config[:kafka_home]}/bin/kafka-run-class.sh"
91
- unknown "Can not find #{kafka_run_class}" unless File.exist?(kafka_run_class)
92
-
93
- cmd = "#{kafka_run_class} kafka.tools.ConsumerOffsetChecker --group #{config[:group]} --zookeeper #{config[:zookeeper]}"
94
- cmd += " --topic #{config[:topic]}" if config[:topic]
95
-
96
- results = run_cmd(cmd)
97
-
98
- [:offset, :logsize, :lag].each do |field|
99
- sum_by_group = results.group_by { |h| h[:topic] }.map do |k, v|
100
- Hash[k, v.inject(0) { |a, e| a + e[field].to_i }]
101
- end
102
- sum_by_group.delete_if { |x| config[:topic_excludes].include?(x.keys[0]) } if config[:topic_excludes]
103
- sum_by_group.each do |x|
104
- output "#{config[:scheme]}.#{config[:group]}.#{x.keys[0]}.#{field}", x.values[0]
105
- end
87
+ [:offset, :logsize, :lag].each do |field|
88
+ consumers.each do |k, v|
89
+ critical "Topic #{k} has #{field} < 0 '#{v[field]}'" unless v.select { |w| w[field].to_i < 0 }.empty?
90
+ end
91
+ end
92
+
93
+ [:offset, :logsize, :lag].each do |field|
94
+ sum_by_group = consumers.map do |k, v|
95
+ Hash[k, v.inject(0) { |a, e| a + e[field].to_i }]
96
+ end
97
+ sum_by_group.each do |x|
98
+ output "#{config[:scheme]}.#{config[:group]}.#{x.keys[0]}.#{field}", x.values[0]
106
99
  end
107
- rescue => e
108
- critical "Error: exception: #{e}"
109
100
  end
110
101
  ok
102
+ rescue => e
103
+ critical "Error: exception: #{e}"
111
104
  end
112
105
  end
@@ -5,8 +5,8 @@ module SensuPluginsKafka
5
5
  # This defines the version of the gem
6
6
  module Version
7
7
  MAJOR = 0
8
- MINOR = 8
9
- PATCH = 1
8
+ MINOR = 9
9
+ PATCH = 0
10
10
 
11
11
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
12
12
  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.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sensu-Plugins and contributors