Class: Ask::Monitoring::Metrics::ErrorCount

Inherits:
Base
  • Object
show all
Defined in:
lib/ask/monitoring/metrics/error_count.rb

Overview

Computes error count over time chart data.

Instance Attribute Summary

Attributes inherited from Base

#scope

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Ask::Monitoring::Metrics::Base

Instance Method Details

#as_chart_dataObject



6
7
8
9
10
11
12
# File 'lib/ask/monitoring/metrics/error_count.rb', line 6

def as_chart_data
  scope
    .where.not(error: nil)
    .group_by_period(:hour, :created_at)
    .count
    .map { |date, value| { date: date, value: value } }
end

#rateFloat

Returns Error rate as a decimal (0.0 – 1.0).

Returns:

  • (Float)

    Error rate as a decimal (0.0 – 1.0)



15
16
17
18
19
# File 'lib/ask/monitoring/metrics/error_count.rb', line 15

def rate
  total = scope.count
  return 0.0 if total.zero?
  scope.where.not(error: nil).count.to_f / total
end