Class: Karafka::Web::Ui::Models::Metrics::Charts::Aggregated
- Inherits:
-
Lib::HashProxy
- Object
- Lib::HashProxy
- Karafka::Web::Ui::Models::Metrics::Charts::Aggregated
- Defined in:
- lib/karafka/web/ui/models/metrics/charts/aggregated.rb
Overview
Model for formatting aggregated metrics data for charts
Instance Method Summary collapse
-
#active_listeners ⇒ Array<Array<Symbol, Integer>>
Active listeners statistics.
-
#data_transfers ⇒ String
JSON with bytes sent and bytes received metrics.
-
#initialize(aggregated, period) ⇒ Aggregated
constructor
A new instance of Aggregated.
-
#method_missing(method_name, *arguments) ⇒ Object
Handles delegation to fetch appropriate historical metrics based on their name.
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
-
#standby_listeners ⇒ Array<Array<Symbol, Integer>>
Standby listeners statistics.
-
#with(*args) ⇒ String
JSON with data about all the charts we were interested in.
Methods inherited from Lib::HashProxy
Constructor Details
#initialize(aggregated, period) ⇒ Aggregated
Returns a new instance of Aggregated.
14 15 16 17 |
# File 'lib/karafka/web/ui/models/metrics/charts/aggregated.rb', line 14 def initialize(aggregated, period) @period = period @data = aggregated.to_h.fetch(period) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments) ⇒ Object
Handles delegation to fetch appropriate historical metrics based on their name
70 71 72 73 74 75 76 |
# File 'lib/karafka/web/ui/models/metrics/charts/aggregated.rb', line 70 def method_missing(method_name, *arguments) if @data.last.last.key?(method_name.to_sym) @data.map { |a| [a.first, a.last[method_name]] } else super end end |
Instance Method Details
#active_listeners ⇒ Array<Array<Symbol, Integer>>
Returns active listeners statistics.
47 48 49 50 51 |
# File 'lib/karafka/web/ui/models/metrics/charts/aggregated.rb', line 47 def active_listeners listeners.map do |listener| [listener[0], listener[1].fetch(:active)] end end |
#data_transfers ⇒ String
Returns JSON with bytes sent and bytes received metrics.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/karafka/web/ui/models/metrics/charts/aggregated.rb', line 20 def data_transfers scale_factor = Processing::TimeSeriesTracker::TIME_RANGES .fetch(@period) .fetch(:resolution) .then { |factor| factor / 1_024.to_f } received = bytes_received.map do |element| [element[0], element[1] * scale_factor] end sent = bytes_sent.map do |element| [element[0], element[1] * scale_factor] end { received: received, sent: sent }.to_json end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
62 63 64 |
# File 'lib/karafka/web/ui/models/metrics/charts/aggregated.rb', line 62 def respond_to_missing?(method_name, include_private = false) @data.last.last.key?(method_name.to_sym) || super end |
#standby_listeners ⇒ Array<Array<Symbol, Integer>>
Returns standby listeners statistics.
54 55 56 57 58 |
# File 'lib/karafka/web/ui/models/metrics/charts/aggregated.rb', line 54 def standby_listeners listeners.map do |listener| [listener[0], listener[1].fetch(:standby)] end end |
#with(*args) ⇒ String
Returns JSON with data about all the charts we were interested in.
39 40 41 42 43 44 |
# File 'lib/karafka/web/ui/models/metrics/charts/aggregated.rb', line 39 def with(*args) args .map { |name| [name.to_sym, public_send(name)] } .to_h .to_json end |