Class: Ktl::ClusterStatsTask

Inherits:
Object
  • Object
show all
Defined in:
lib/ktl/cluster_stats_task.rb

Instance Method Summary collapse

Constructor Details

#initialize(zk_client, shell) ⇒ ClusterStatsTask

Returns a new instance of ClusterStatsTask.



5
6
7
8
# File 'lib/ktl/cluster_stats_task.rb', line 5

def initialize(zk_client, shell)
  @zk_client = zk_client
  @shell = shell
end

Instance Method Details

#executeObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ktl/cluster_stats_task.rb', line 10

def execute
  brokers = @zk_client.brokers
  partitions = @zk_client.all_partitions
  topics = extract_topics(partitions)
  leaders = @zk_client.leader_and_isr_for(partitions)
  ownership = broker_ownership(leaders)
  @shell.say 'Cluster status:'
  @shell.say '  topics: %d (%d partitions)' % [topics.size, partitions.size]
  @shell.say '  brokers: %d' % [brokers.size]
  brokers.foreach do |broker|
    leader_for = ownership[broker.id]
    share = leader_for.fdiv(partitions.size.to_f) * 100
    @shell.say '    - %s leader for %d partitions (%.2f %%)' % [broker.to_s, leader_for, share]
  end
end