Class: Karafka::Web::Ui::Models::Topic
- Inherits:
-
Lib::HashProxy
- Object
- Lib::HashProxy
- Karafka::Web::Ui::Models::Topic
- Defined in:
- lib/karafka/web/ui/models/topic.rb
Overview
Single topic data representation model
Class Method Summary collapse
-
.all ⇒ Array<Broker>
All topics in the cluster.
-
.find(topic_name) ⇒ Topic
Finds requested topic.
Instance Method Summary collapse
-
#configs ⇒ Array<Karafka::Admin::Configs::Config>
All topic configs.
-
#distribution(partitions) ⇒ Array<HashProxy, Array<HashProxy>>
Generates info about estimated messages distribution in partitions, allowing for inspection and detection of imbalances.
-
#partitions ⇒ Array<Partition>
All topic partitions data.
Methods inherited from Lib::HashProxy
#initialize, #method_missing, #respond_to_missing?, #to_h
Constructor Details
This class inherits a constructor from Karafka::Web::Ui::Lib::HashProxy
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Karafka::Web::Ui::Lib::HashProxy
Class Method Details
.all ⇒ Array<Broker>
Returns all topics in the cluster.
11 12 13 14 15 |
# File 'lib/karafka/web/ui/models/topic.rb', line 11 def all ClusterInfo.fetch.topics.map do |topic| new(topic) end end |
Instance Method Details
#configs ⇒ Array<Karafka::Admin::Configs::Config>
Returns all topic configs.
41 42 43 44 45 46 47 48 |
# File 'lib/karafka/web/ui/models/topic.rb', line 41 def configs @configs ||= ::Karafka::Admin::Configs.describe( ::Karafka::Admin::Configs::Resource.new( type: :topic, name: topic_name ) ).first.configs.dup end |
#distribution(partitions) ⇒ Array<HashProxy, Array<HashProxy>>
Generates info about estimated messages distribution in partitions, allowing for inspection and detection of imbalances
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/karafka/web/ui/models/topic.rb', line 57 def distribution(partitions) sum = 0.0 avg = 0.0 counts = partitions.map do |partition_id| offsets = Admin.read_watermark_offsets(topic_name, partition_id) count = offsets.last - offsets.first sum += count { count: count, partition_id: partition_id } end avg = sum / counts.size counts.each do |part_stats| count = part_stats[:count] part_stats[:share] = ((count / sum) * 100).round(2) part_stats[:diff] = ((count - avg) / avg) * 100 end variance = counts .map { |part_stats| part_stats[:count] } .sum { |count| (count - avg)**2 } / counts.size std_dev = Math.sqrt(variance) std_dev_rel = ((std_dev / avg) * 100).round(2) [ # round stdev since its message count Lib::HashProxy.new(std_dev: std_dev.round, std_dev_rel: std_dev_rel, sum: sum), counts.map { |part_stats| Lib::HashProxy.new(part_stats) } ] end |