Class: Sidekiq::TUI::Tabs::Home
- Defined in:
- lib/sidekiq/tui/tabs/home.rb
Constant Summary
Constants included from Controls
Controls::GLOBAL, Controls::SHARED
Instance Attribute Summary
Attributes inherited from BaseTab
Instance Method Summary collapse
- #refresh_data ⇒ Object
- #render(tui, frame, area) ⇒ Object
- #render_chart_section(tui, frame, area) ⇒ Object
- #render_redis_info_section(tui, frame, area) ⇒ Object
Methods inherited from BaseTab
#each_selection, #error, #error=, #filtering?, #format_memory, #initialize, #navigate_row, #next_page, #number_with_delimiter, #prev_page, #refresh_data_for_stats, #render_stats_section, #render_table, #reset_data, #selected?, #t, #toggle_select
Methods included from Controls
Constructor Details
This class inherits a constructor from Sidekiq::TUI::BaseTab
Instance Method Details
#refresh_data ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/sidekiq/tui/tabs/home.rb', line 7 def refresh_data refresh_data_for_stats stats = Sidekiq::Stats.new @data[:chart] ||= { previous_stats: { processed: stats.processed, failed: stats.failed }, deltas: { processed: Array.new(50, 0), failed: Array.new(50, 0) } } processed_delta = stats.processed - @data[:chart][:previous_stats][:processed] failed_delta = stats.failed - @data[:chart][:previous_stats][:failed] @data[:chart][:deltas][:processed].shift @data[:chart][:deltas][:processed].push(processed_delta) @data[:chart][:deltas][:failed].shift @data[:chart][:deltas][:failed].push(failed_delta) @data[:chart][:previous_stats] = { processed: stats.processed, failed: stats.failed } redis_info = Sidekiq.default_configuration.redis_info @data[:redis_info] = { version: redis_info["redis_version"] || "N/A", uptime_days: redis_info["uptime_in_days"] || "N/A", connected_clients: redis_info["connected_clients"] || "N/A", used_memory: redis_info["used_memory_human"] || "N/A", peak_memory: redis_info["used_memory_peak_human"] || "N/A" } end |
#render(tui, frame, area) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/sidekiq/tui/tabs/home.rb', line 46 def render(tui, frame, area) chunks = tui.layout_split( area, direction: :vertical, constraints: [ tui.constraint_length(4), # Stats tui.constraint_fill(1), # Graph tui.constraint_length(4) # Redis ] ) render_stats_section(tui, frame, chunks[0]) render_chart_section(tui, frame, chunks[1]) render_redis_info_section(tui, frame, chunks[2]) end |
#render_chart_section(tui, frame, area) ⇒ Object
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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/sidekiq/tui/tabs/home.rb', line 62 def render_chart_section(tui, frame, area) max_value = [@data[:chart][:deltas][:processed].max, @data[:chart][:deltas][:failed].max, 1].max y_max = [max_value, 5].max processed_data = @data[:chart][:deltas][:processed].each_with_index.map { |value, idx| [idx.to_f, value.to_f] } failed_data = @data[:chart][:deltas][:failed].each_with_index.map { |value, idx| [idx.to_f, value.to_f] } datasets = [ tui.dataset( name: "", data: processed_data, style: tui.style(fg: :green), marker: :dot, graph_type: :line ), tui.dataset( name: "", data: failed_data, style: tui.style(fg: :red), marker: :dot, graph_type: :line ) ] num_labels = 5 y_labels = (0...num_labels).map do |i| value = ((y_max * i) / (num_labels - 1)).round value.to_s end beacon_pulse = (Time.now.to_i % 2 == 0) ? "●" : " " chart = tui.chart( datasets: datasets, x_axis: tui.axis( bounds: [0.0, 49.0], labels: [], style: tui.style(fg: :white) ), y_axis: tui.axis( bounds: [0.0, y_max.to_f], labels: y_labels, style: tui.style(fg: :white) ), block: tui.block( title: "Dashboard #{beacon_pulse}", borders: [:all] ) ) frame.(chart, area) end |
#render_redis_info_section(tui, frame, area) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/sidekiq/tui/tabs/home.rb', line 115 def render_redis_info_section(tui, frame, area) redis_info = @data[:redis_info] uptime_value = (redis_info[:uptime_days] == "N/A") ? "N/A" : "#{redis_info[:uptime_days]} days" keys = ["Version", "Uptime", "Connected Clients", "Memory Usage", "Peak Memory"] values = [ redis_info[:version].to_s, uptime_value, redis_info[:connected_clients].to_s, redis_info[:used_memory].to_s, redis_info[:peak_memory].to_s ] # Format keys and values with spacing keys_line = keys.map { |k| t(k).ljust(18) }.join(" ") values_line = values.map { |v| v.ljust(18) }.join(" ") frame.( tui.paragraph( text: [keys_line, values_line], block: tui.block(title: "Redis Information", borders: [:all]) ), area ) end |