Class: Karafka::Web::Tracking::Consumers::Sampler::Metrics::Jobs
- Includes:
- Core::Helpers::Time
- Defined in:
- lib/karafka/web/tracking/consumers/sampler/metrics/jobs.rb
Overview
Collects job queue statistics and worker utilization metrics
Instance Method Summary collapse
-
#initialize(windows, started_at, workers) ⇒ Jobs
constructor
A new instance of Jobs.
-
#jobs_queue_statistics ⇒ Hash
Job queue statistics.
-
#utilization ⇒ Numeric
% utilization of all the threads.
Constructor Details
#initialize(windows, started_at, workers) ⇒ Jobs
Returns a new instance of Jobs.
16 17 18 19 20 21 |
# File 'lib/karafka/web/tracking/consumers/sampler/metrics/jobs.rb', line 16 def initialize(windows, started_at, workers) super() @windows = windows @started_at = started_at @workers = workers end |
Instance Method Details
#jobs_queue_statistics ⇒ Hash
Returns job queue statistics.
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/karafka/web/tracking/consumers/sampler/metrics/jobs.rb', line 39 def jobs_queue_statistics # We return empty stats in case jobs queue is not yet initialized base = Karafka::Server.jobs_queue&.statistics || { busy: 0, enqueued: 0 } stats = base.slice(:busy, :enqueued, :waiting) stats[:waiting] ||= 0 # busy - represents number of jobs that are being executed currently # enqueued - jobs that are in the queue but not being picked up yet # waiting - jobs that are not scheduled on the queue but will be # be enqueued in case of advanced schedulers stats end |
#utilization ⇒ Numeric
Returns % utilization of all the threads. 100% means all the threads are utilized all the time within the given time window. 0% means, nothing is happening most if not all the time.
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/karafka/web/tracking/consumers/sampler/metrics/jobs.rb', line 26 def utilization totals = windows.m1[:processed_total_time] return 0 if totals.empty? timefactor = [float_now - started_at, 60].min # We divide by 1_000 to convert from milliseconds # We multiply by 100 to have it in % scale (totals.sum / 1_000 / workers / timefactor * 100).round(2) end |