module Aeternitas::Metrics
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: @example
Aeternitas::Metrics.polls MyPollable, from: 3.days.ago, to: Time.now, resolution: :hour Aeternitas::Metrics.execution_times MyPollable
@see get
Constants
- AVAILABLE_METRICS
Public Class Methods
Computes the ratio of a base counter time series and a target counter time series @param [Array] base base time series data @param [Array] target target time series data @return [Array] ratio time series data
# 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
Returns the failure ratio of the given job for given time frame and resolution @param [Symbol String] name the metric @param [Object] pollable_class the pollable class @param [DateTime] from begin of the time frame @param [DateTime] to end of the timeframe @param [Symbol] resolution resolution @return [Aeternitas::Metrics::Ratio] ratio time series
# 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
Retrieves the stats of the given metric in the given time frame and resolution. @param [Symbol String] name the metric @param [Object] pollable_class the pollable class @param [DateTime] from begin of the time frame @param [DateTime] to end of the timeframe @param [Symbol] resolution resolution @return [Aeternitas::Metrics::Counter, Aeternitas::Metrics::Value] stats
# 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
Computes the metric key of a given metric-pollable pair @param [Symbol, String] name the metric @param [Object] pollable_class pollable class @return [String] the metric key
# File lib/aeternitas/metrics.rb, line 145 def self.get_key(name, pollable_class) "#{name}:#{pollable_class.name}" end
Returns the lock ratio of the given job for given time frame and resolution @param [Symbol String] name the metric @param [Object] pollable_class the pollable class @param [DateTime] from begin of the time frame @param [DateTime] to end of the timeframe @param [Symbol] resolution resolution @return [Aeternitas::Metrics::Ratio] ratio time series
# 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
Increses the specified counter metric for the given pollable. @param [Symbol, String] name the metric @param [Pollable] pollable_class pollable instance
# 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
Logs a value in a value metric for the given pollable. @param [Symbol String] name the metric @param [Pollable] pollable_class pollable instance @param [Object] value the value
# 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