Skip to content

Commit

Permalink
Merge pull request #14 from AndyObtiva/development
Browse files Browse the repository at this point in the history
Dashboard graph assuming a 1 second polling interval + Rename GUI to KuiqApplication
  • Loading branch information
mperham authored Nov 30, 2023
2 parents 9477c17 + 40ef1c9 commit 4190d20
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 27 deletions.
12 changes: 10 additions & 2 deletions lib/kuiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
require "kuiq/version"

module Kuiq
WINDOW_WIDTH = 900
WINDOW_HEIGHT = 500
WINDOW_WIDTH = 900.0
WINDOW_HEIGHT = 500.0
GRAPH_WIDTH = 885.0
GRAPH_HEIGHT = 200.0
GRAPH_PADDING_HEIGHT = 5.0
GRAPH_PADDING_WIDTH = 5.0
GRAPH_POINT_DISTANCE = 15.0
GRAPH_MAX_POINTS = (GRAPH_WIDTH/GRAPH_POINT_DISTANCE).to_i + 2
GRAPH_MAX_PROCESSED = 20
GRAPH_DASHBOARD_COLOR = [47, 109, 104]
end
2 changes: 1 addition & 1 deletion lib/kuiq/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def parse
end

def gui
require "kuiq/gui"
require "kuiq/view/kuiq_application"
Kuiq::GUI.launch
end

Expand Down
34 changes: 18 additions & 16 deletions lib/kuiq/model/job_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ module Model
class JobManager
REDIS_PROPERTIES = %w[redis_version uptime_in_days connected_clients used_memory_human used_memory_peak_human]

attr_accessor :jobs, :polling_interval
attr_accessor :polling_interval
attr_reader :redis_url, :redis_info, :current_time

def initialize
@jobs = []
@polling_interval = 5
@polling_interval = 1
@redis_url = Sidekiq.redis { |c| c.config.server_url }
@redis_info = Sidekiq.default_configuration.redis_info
@current_time = Time.now.utc
@processed_stats = []
end

def stats
Expand Down Expand Up @@ -98,29 +98,31 @@ def refresh_redis_properties
redis_info.notify_observers(property)
end
end

def record_stats
@processed_stats.prepend({time: Time.now.utc.strftime("%H:%M:%S UTC"), processed: processed})
@processed_stats = @processed_stats[0, 61]
end

def report_points
points = []
current_jobs = jobs.dup
start_time = @current_time
end_time = Time.now
time_length = (end_time - start_time).to_i
time_length.times do |n|
job_found = current_jobs.detect do |job|
job_delay = job.time - start_time
job_delay.between?(n, n + 1)
end
x = n * 15
y = job_found ? 5 : 195
current_jobs = @processed_stats
return points if current_jobs.size <= 1
current_jobs.each_with_index do |job, n|
next if n == 0
jobs_processed = current_jobs[n-1][:processed] - job[:processed]
jobs_processed = [jobs_processed, GRAPH_MAX_PROCESSED].min
x = GRAPH_WIDTH - ((n - 1) * GRAPH_POINT_DISTANCE) - GRAPH_PADDING_WIDTH
y = ((GRAPH_HEIGHT - GRAPH_PADDING_HEIGHT) - jobs_processed*((GRAPH_HEIGHT - GRAPH_PADDING_HEIGHT*2)/GRAPH_MAX_PROCESSED))
points << [x, y]
end
translate_points(points)
points
end

def translate_points(points)
max_job_count_before_translation = ((800 / 15).to_i + 1)
x_translation = [(points.size - max_job_count_before_translation) * 15, 0].max
max_job_count_before_translation = ((GRAPH_WIDTH / GRAPH_POINT_DISTANCE).to_i + 1)
x_translation = [(points.size - max_job_count_before_translation) * GRAPH_POINT_DISTANCE, 0].max
if x_translation > 0
points.each do |point|
point[0] = point[0] - x_translation
Expand Down
7 changes: 4 additions & 3 deletions lib/kuiq/view/dashboard_graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class DashboardGraph
time_remaining = job_manager.polling_interval
timer_interval = 1 # 1 second
Glimmer::LibUI.timer(timer_interval) do
job_manager.record_stats
if polling_interval != job_manager.polling_interval
if job_manager.polling_interval < polling_interval
time_remaining = job_manager.polling_interval
Expand All @@ -33,19 +34,19 @@ class DashboardGraph
area {
stretchy false

rectangle(0, 0, WINDOW_WIDTH, 200) {
rectangle(0, 0, WINDOW_WIDTH, GRAPH_HEIGHT) {
fill 255, 255, 255
}

on_draw do
last_point = nil
job_manager.report_points.each do |point|
circle(point.first, point.last, 3) {
fill 0, 128, 0
fill *GRAPH_DASHBOARD_COLOR
}
if last_point
line(last_point.first, last_point.last, point.first, point.last) {
stroke 0, 128, 0, thickness: 2
stroke *GRAPH_DASHBOARD_COLOR, thickness: 2
}
end
last_point = point
Expand Down
6 changes: 1 addition & 5 deletions lib/kuiq/gui.rb → lib/kuiq/view/kuiq_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ class GUI
@job_manager = Model::JobManager.new
end

after_body do
# generate_jobs
end

body {
window("Sidekiq UI", WINDOW_WIDTH, WINDOW_HEIGHT) {
window("Kuiq - Sidekiq UI", WINDOW_WIDTH, WINDOW_HEIGHT) {
vertical_box {
tab {
tab_item(t("Dashboard")) {
Expand Down

0 comments on commit 4190d20

Please sign in to comment.