Class: Sidekiq::TUI::Tabs::Metrics
- Includes:
- Filtering
- Defined in:
- lib/sidekiq/tui/tabs/metrics.rb
Constant Summary collapse
- COLORS =
%i[light_blue light_cyan light_yellow light_red light_green white gray]
Constants inherited from BaseTab
Constants included from Controls
Controls::GLOBAL, Controls::SHARED
Instance Attribute Summary
Attributes inherited from BaseTab
Instance Method Summary collapse
- #features ⇒ Object
- #on_filter_change ⇒ Object
- #refresh_data ⇒ Object
- #regexp ⇒ Object
- #render(tui, frame, area) ⇒ Object
-
#render_metrics_chart(tui, frame, area) ⇒ Object
Run to generate metrics data: cd myapp && bundle install bundle exec rake seed_jobs bundle exec sidekiq.
Methods included from Filtering
#append_to_filter, #current_filter, #filtering?, #remove_last_char_from_filter, #start_filtering, #stop_and_clear_filtering, #stop_filtering
Methods inherited from BaseTab
#chart_y_axis, #each_selection, #error, #error=, #filtering?, #format_memory, #initialize, #navigate_row, #next_page, #number_with_delimiter, #prev_page, #refresh_data_for_stats, #render_kv_section, #render_stats_section, #render_table, #reset_data, #selected?, #stats_content_split, #striped_rows, #t, #toggle_select
Methods included from Controls
Constructor Details
This class inherits a constructor from Sidekiq::TUI::BaseTab
Instance Method Details
#features ⇒ Object
11 12 13 |
# File 'lib/sidekiq/tui/tabs/metrics.rb', line 11 def features %i[filterable] end |
#on_filter_change ⇒ Object
15 16 17 |
# File 'lib/sidekiq/tui/tabs/metrics.rb', line 15 def on_filter_change @data[:metrics_refresh] = nil end |
#refresh_data ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sidekiq/tui/tabs/metrics.rb', line 23 def refresh_data refresh_data_for_stats # only need to refresh every 60 seconds if !@data[:metrics_refresh] || @data[:metrics_refresh] < Time.now q = Sidekiq::Metrics::Query.new query_result = q.top_jobs(class_filter: regexp, minutes: 60) @data[:metrics] = query_result @data[:metrics_refresh] = Time.now + 60 end end |
#regexp ⇒ Object
19 20 21 |
# File 'lib/sidekiq/tui/tabs/metrics.rb', line 19 def regexp filtering? ? Regexp.new(Regexp.escape(current_filter), Regexp::IGNORECASE) : nil end |
#render(tui, frame, area) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/sidekiq/tui/tabs/metrics.rb', line 35 def render(tui, frame, area) chunks = stats_content_split(tui, area) render_stats_section(tui, frame, chunks[0]) render_metrics_chart(tui, frame, chunks[1]) end |
#render_metrics_chart(tui, frame, area) ⇒ Object
Run to generate metrics data:
cd myapp && bundle install
bundle exec rake seed_jobs
bundle exec sidekiq
46 47 48 49 50 51 52 53 54 55 56 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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/sidekiq/tui/tabs/metrics.rb', line 46 def render_metrics_chart(tui, frame, area) y_max = 5 csize = COLORS.size q = @data[:metrics] job_results = q.job_results.sort_by { |(kls, jr)| jr.totals["s"] }.reverse.first(COLORS.size) # visible_kls = job_results.first(5).map(&:first) # chart_data = { # series: job_results.map { |(kls, jr)| [kls, jr.dig("series", "s")] }.to_h, # marks: query_result.marks.map { |m| [m.bucket, m.label] }, # starts_at: query_result.starts_at.iso8601, # ends_at: query_result.ends_at.iso8601, # visibleKls: visible_kls, # yLabel: 'TotalExecutionTime', # units: 'seconds', # markLabel: '*', # } datasets = job_results.map.with_index do |(kls, data), idx| # log kls, data, idx hrdata = data.dig("series", "s") tm = Time.now tmi = tm.to_i tm = Time.at(tmi - (tmi % 60)).utc data = Array.new(60) { |idx| idx }.map do |bucket_idx| jumpback = bucket_idx * 60 value = hrdata[(tm - jumpback).iso8601] || 0 y_max = value if value > y_max # we have 60 data points, newest data should be # at highest indexes so we have to rejigger the index # here [59 - bucket_idx, value] end # log data # log(data) tui.dataset(name: kls, data: data, style: tui.style(fg: COLORS[idx % csize]), marker: :dot, graph_type: :line) end xlabels = [ q.starts_at.iso8601[11..15], q.ends_at.iso8601[11..15] ] # beacon_pulse = (Time.now.to_i % 2 == 0) ? "●" : " " chart = tui.chart( datasets: datasets, x_axis: tui.axis( bounds: [0.0, 60.0], labels: xlabels, style: tui.style(fg: :white) ), y_axis: chart_y_axis(tui, y_max), block: tui.block( title: t(name), borders: [:all] ) ) frame.(chart, area) end |