Class: Sidekiq::Metrics::Query::JobResult
- Inherits:
-
Struct
- Object
- Struct
- Sidekiq::Metrics::Query::JobResult
- Defined in:
- lib/sidekiq/metrics/query.rb
Instance Attribute Summary collapse
-
#granularity ⇒ Object
Returns the value of attribute granularity.
-
#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(granularity = :minutely) ⇒ JobResult
constructor
A new instance of JobResult.
- #series_avg(metric = "ms") ⇒ Object
- #total_avg(metric = "ms") ⇒ Object
Constructor Details
#initialize(granularity = :minutely) ⇒ JobResult
Returns a new instance of JobResult.
126 127 128 129 130 131 132 |
# File 'lib/sidekiq/metrics/query.rb', line 126 def initialize(granularity = :minutely) super self.granularity = granularity 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
#granularity ⇒ Object
Returns the value of attribute granularity
125 126 127 |
# File 'lib/sidekiq/metrics/query.rb', line 125 def granularity @granularity end |
#hist ⇒ Object
Returns the value of attribute hist
125 126 127 |
# File 'lib/sidekiq/metrics/query.rb', line 125 def hist @hist end |
#series ⇒ Object
Returns the value of attribute series
125 126 127 |
# File 'lib/sidekiq/metrics/query.rb', line 125 def series @series end |
#totals ⇒ Object
Returns the value of attribute totals
125 126 127 |
# File 'lib/sidekiq/metrics/query.rb', line 125 def totals @totals end |
Instance Method Details
#add_hist(time, hist_result) ⇒ Object
142 143 144 |
# File 'lib/sidekiq/metrics/query.rb', line 142 def add_hist(time, hist_result) hist[Query.bkt_time_s(time, granularity)] = hist_result end |
#add_metric(metric, time, value) ⇒ Object
134 135 136 137 138 139 140 |
# File 'lib/sidekiq/metrics/query.rb', line 134 def add_metric(metric, time, value) totals[metric] += value series[metric][Query.bkt_time_s(time, granularity)] += value # Include timing measurements in seconds for convenience add_metric("s", time, value / 1000.0) if metric == "ms" end |
#series_avg(metric = "ms") ⇒ Object
152 153 154 155 156 157 |
# File 'lib/sidekiq/metrics/query.rb', line 152 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
146 147 148 149 150 |
# File 'lib/sidekiq/metrics/query.rb', line 146 def total_avg(metric = "ms") completed = totals["p"] - totals["f"] return 0 if completed.zero? totals[metric].to_f / completed end |