Skip to content

Commit

Permalink
Creates SystemStatusController and SystemMetricsService for status in…
Browse files Browse the repository at this point in the history
…fo UI + Defines functions to get stats and queue info from Sidekiq
  • Loading branch information
empty-codes committed Dec 18, 2024
1 parent a8b016d commit d19a4a0
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/controllers/system_status_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class SystemStatusController < ApplicationController
# service = SystemMetricsService.new
end
52 changes: 52 additions & 0 deletions app/services/get_system_metrics.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# frozen_string_literal: true

require 'sidekiq/api'

class SystemMetricsService
def initialize
@queues = YAML.load_file('config/sidekiq.yml')[:queues]
fetch_sidekiq_stats
end

def fetch_sidekiq_stats
stats = Sidekiq::Stats.new

@processed_jobs_stat = stats.processed
@failed_jobs_stat = stats.failed # Failed Job Retention
@enqueued_jobs_stat = stats.enqueued
@scheduled_jobs_stat = stats.scheduled_size

# also allow stats from selected dates to be viewed
# using Stats::History
end

# def fetch_system_health_metrics
# end

# def fetch_reliability_metrics
# end

# def fetch_availability_metrics
# end

# def fetch_processing_efficiency_metrics
# end

# def fetch_resource_utilization_metrics
# end

def fetch_queue_management_metrics
# Queue latency; how long jobs wait in the queue before processing
@queues.map do |queue_name|
queue = Sidekiq::Queue.new(queue_name)
{
name: queue.name,
size: queue.size,
latency: queue.latency
}
end
end

# def fetch_data_freshness_metrics
# end
end

0 comments on commit d19a4a0

Please sign in to comment.