Class: Sidekiq::Metrics::Query::JobResult
- Inherits:
-
Struct
- Object
- Struct
- Sidekiq::Metrics::Query::JobResult
- Defined in:
- lib/sidekiq/metrics/query.rb
Instance Attribute Summary collapse
-
#hist ⇒ Object
Returns the value of attribute hist.
-
#series ⇒ Object
Returns the value of attribute series.
-
#totals ⇒ Object
Returns the value of attribute totals.
Instance Method Summary collapse
- #add_hist(time, hist_result) ⇒ Object
- #add_metric(metric, time, value) ⇒ Object
-
#initialize ⇒ JobResult
constructor
A new instance of JobResult.
- #series_avg(metric = "ms") ⇒ Object
- #total_avg(metric = "ms") ⇒ Object
Constructor Details
#initialize ⇒ JobResult
Returns a new instance of JobResult.
103 104 105 106 107 108 |
# File 'lib/sidekiq/metrics/query.rb', line 103 def initialize super self.series = Hash.new { |h, k| h[k] = Hash.new(0) } self.hist = Hash.new { |h, k| h[k] = [] } self.totals = Hash.new(0) end |
Instance Attribute Details
#hist ⇒ Object
Returns the value of attribute hist
102 103 104 |
# File 'lib/sidekiq/metrics/query.rb', line 102 def hist @hist end |
#series ⇒ Object
Returns the value of attribute series
102 103 104 |
# File 'lib/sidekiq/metrics/query.rb', line 102 def series @series end |
#totals ⇒ Object
Returns the value of attribute totals
102 103 104 |
# File 'lib/sidekiq/metrics/query.rb', line 102 def totals @totals end |
Instance Method Details
#add_hist(time, hist_result) ⇒ Object
118 119 120 |
# File 'lib/sidekiq/metrics/query.rb', line 118 def add_hist(time, hist_result) hist[time.strftime("%H:%M")] = hist_result end |
#add_metric(metric, time, value) ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/sidekiq/metrics/query.rb', line 110 def add_metric(metric, time, value) totals[metric] += value series[metric][time.strftime("%H:%M")] += value # Include timing measurements in seconds for convenience add_metric("s", time, value / 1000.0) if metric == "ms" end |
#series_avg(metric = "ms") ⇒ Object
128 129 130 131 132 133 |
# File 'lib/sidekiq/metrics/query.rb', line 128 def series_avg(metric = "ms") series[metric].each_with_object(Hash.new(0)) do |(bucket, value), result| completed = series.dig("p", bucket) - series.dig("f", bucket) result[bucket] = (completed == 0) ? 0 : value.to_f / completed end end |
#total_avg(metric = "ms") ⇒ Object
122 123 124 125 126 |
# File 'lib/sidekiq/metrics/query.rb', line 122 def total_avg(metric = "ms") completed = totals["p"] - totals["f"] return 0 if completed.zero? totals[metric].to_f / completed end |