Module: Aeternitas::Metrics
- Defined in:
- lib/aeternitas/metrics.rb,
lib/aeternitas/metrics/ratio.rb,
lib/aeternitas/metrics/values.rb,
lib/aeternitas/metrics/counter.rb,
lib/aeternitas/metrics/ten_minutes_resolution.rb
Overview
Provides extensive metrics for Aeternitas. Every metric is scoped by pollable class. Available metrics are:
- polls => Number of polling runs
- successful_polls => Number of successful polling runs
- failed_polls => Number of failed polling runs (includes IgnoredErrors,
excludes deactivation errors and Lock errors)
- ignored_errors => Number of raised {Aeternitas::Errors::Ignored}
- deactivation_errors => Number of errors raised which are declared as deactivation_errors
- execution_time => Job execution time in seconds
- guard_locked => Number of encountered locked guards
- guard_timeout => Time until the guard is unlocked in seconds
- guard_timeout_exceeded => Number of jobs that ran longer than the guards timeout
- pollables_created => Number of created pollables
- sources_created => Number of created sources
Available Resolutions are:
- :minute (stored for 3 days)
- :ten_minutes (stored for 14 days)
- :hour (stored for 2 months)
- :day (stored indefinitely)
Every metric can be accessed via a getter method:
Defined Under Namespace
Modules: TenMinutesResolution Classes: Counter, Ratio, Values
Constant Summary collapse
- AVAILABLE_METRICS =
{ polls: :counter, successful_polls: :counter, failed_polls: :counter, ignored_errors: :counter, deactivations: :counter, execution_time: :value, guard_locked: :counter, guard_timeout: :value, guard_timeout_exceeded: :counter, sources_created: :counter, pollables_created: :counter }.freeze
Class Method Summary collapse
-
.calculate_ratio(base, target) ⇒ Array
Computes the ratio of a base counter time series and a target counter time series.
-
.failure_ratio(pollable_class, from: 1.hour.ago, to: Time.now, resolution: :minute) ⇒ Aeternitas::Metrics::Ratio
Returns the failure ratio of the given job for given time frame and resolution.
-
.get(name, pollable_class, from: 1.hour.ago, to: Time.now, resolution: :minute) ⇒ Aeternitas::Metrics::Counter, Aeternitas::Metrics::Value
Retrieves the stats of the given metric in the given time frame and resolution.
-
.get_key(name, pollable_class) ⇒ String
Computes the metric key of a given metric-pollable pair.
-
.guard_locked_ratio(pollable_class, from: 1.hour.ago, to: Time.now, resolution: :minute) ⇒ Aeternitas::Metrics::Ratio
Returns the lock ratio of the given job for given time frame and resolution.
-
.log(name, pollable_class) ⇒ Object
Increses the specified counter metric for the given pollable.
-
.log_value(name, pollable_class, value) ⇒ Object
Logs a value in a value metric for the given pollable.
Class Method Details
.calculate_ratio(base, target) ⇒ Array
Computes the ratio of a base counter time series and a target counter time series
153 154 155 156 157 158 159 160 |
# File 'lib/aeternitas/metrics.rb', line 153 def self.calculate_ratio(base, target) base.zip(target).map do |b, t| { timestamp: b['timestamp'], ratio: b['count'].to_i.zero? ? 0 : t['count'].to_i / b['count'].to_f }.with_indifferent_access end end |
.failure_ratio(pollable_class, from: 1.hour.ago, to: Time.now, resolution: :minute) ⇒ Aeternitas::Metrics::Ratio
Returns the failure ratio of the given job for given time frame and resolution
122 123 124 125 126 |
# File 'lib/aeternitas/metrics.rb', line 122 def self.failure_ratio(pollable_class, from: 1.hour.ago, to: Time.now, resolution: :minute) polls = polls(pollable_class, from: from, to: to, resolution: resolution) failed_polls = failed_polls(pollable_class, from: from, to: to, resolution: resolution) Ratio.new(from, to, resolution, calculate_ratio(polls, failed_polls)) end |
.get(name, pollable_class, from: 1.hour.ago, to: Time.now, resolution: :minute) ⇒ Aeternitas::Metrics::Counter, Aeternitas::Metrics::Value
Retrieves the stats of the given metric in the given time frame and resolution.
101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/aeternitas/metrics.rb', line 101 def self.get(name, pollable_class, from: 1.hour.ago, to: Time.now, resolution: :minute) raise('Metric not found') unless AVAILABLE_METRICS.key? name raise('Invalid interval') if from > to result = TabsTabs.get_stats(get_key(name, pollable_class), from..to, resolution) if AVAILABLE_METRICS[name] == :counter Counter.new(result) else Values.new(result) end rescue TabsTabs::UnknownMetricError => _ TabsTabs.create_metric(get_key(name, pollable_class), AVAILABLE_METRICS[name].to_s) get(name, pollable_class, from: from, to: to, resolution: resolution) end |
.get_key(name, pollable_class) ⇒ String
Computes the metric key of a given metric-pollable pair
145 146 147 |
# File 'lib/aeternitas/metrics.rb', line 145 def self.get_key(name, pollable_class) "#{name}:#{pollable_class.name}" end |
.guard_locked_ratio(pollable_class, from: 1.hour.ago, to: Time.now, resolution: :minute) ⇒ Aeternitas::Metrics::Ratio
Returns the lock ratio of the given job for given time frame and resolution
135 136 137 138 139 |
# File 'lib/aeternitas/metrics.rb', line 135 def self.guard_locked_ratio(pollable_class, from: 1.hour.ago, to: Time.now, resolution: :minute) polls = polls(pollable_class, from: from, to: to, resolution: resolution) guard_locked = guard_locked(pollable_class, from: from, to: to, resolution: resolution) Ratio.new(from, to, resolution, calculate_ratio(polls, guard_locked)) end |
.log(name, pollable_class) ⇒ Object
Increses the specified counter metric for the given pollable.
72 73 74 75 76 77 78 79 |
# File 'lib/aeternitas/metrics.rb', line 72 def self.log(name, pollable_class) raise('Metric not found') unless AVAILABLE_METRICS.key? name raise ArgumentError, "#{name} isn't a Counter" unless AVAILABLE_METRICS[name] == :counter begin TabsTabs.increment_counter(get_key(name, pollable_class)) TabsTabs.increment_counter(get_key(name, Aeternitas::Pollable)) rescue StandardError ; end end |
.log_value(name, pollable_class, value) ⇒ Object
Logs a value in a value metric for the given pollable.
85 86 87 88 89 90 91 92 |
# File 'lib/aeternitas/metrics.rb', line 85 def self.log_value(name, pollable_class, value) raise('Metric not found') unless AVAILABLE_METRICS.key? name raise(ArgumentError, "#{name} isn't a Value") unless AVAILABLE_METRICS[name] == :value begin TabsTabs.record_value(get_key(name, pollable_class), value) TabsTabs.record_value(get_key(name, Aeternitas::Pollable), value) rescue StandardError ; end end |