From 64f6de3c230aac88ea1389f01c95254efdf996a9 Mon Sep 17 00:00:00 2001 From: Olivier Bazoud Date: Thu, 16 Feb 2017 14:17:07 +0100 Subject: [PATCH] Add missing methods --- bin/metrics-consumer.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bin/metrics-consumer.rb b/bin/metrics-consumer.rb index 5ba1881..b1c18e0 100755 --- a/bin/metrics-consumer.rb +++ b/bin/metrics-consumer.rb @@ -60,6 +60,24 @@ class ConsumerOffsetMetrics < Sensu::Plugin::Metric::CLI::Graphite long: '--zookeeper NAME', default: 'localhost:2181' + def kafka_topics(zk, group) + zk.get_children(path: "/consumers/#{group}/owners")[:children].sort + end + + def topics_partitions(zk, topic) + JSON.parse(zk.get(path: "/brokers/topics/#{topic}")[:data])['partitions'].keys.map(&:to_i).sort + end + + def leader_broker(zk, topic, partition) + state = zk.get(path: "/brokers/topics/#{topic}/partitions/#{partition}/state") + leader = JSON.parse(state[:data])['leader'] + JSON.parse(zk.get(path: "/brokers/ids/#{leader}")[:data]) + end + + def consumer_offset(zk, group, topic, partition) + zk.get(path: "/consumers/#{group}/offsets/#{topic}/#{partition}")[:data].to_i + end + def run z = Zookeeper.new(config[:zookeeper])