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])