Module: Aeternitas::Metrics
- Defined in:
- lib/aeternitas/metrics.rb
Overview
Provides a simplified metrics system for Aeternitas. Every metric is scoped by pollable class and logged in the ‘aeternitas_metrics` table.
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}
- deactivations => Number of deactivations
- 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
Constant Summary collapse
- AVAILABLE_METRICS =
A list of all available metric names.
[ :polls, :successful_polls, :failed_polls, :ignored_errors, :deactivations, :execution_time, :guard_locked, :guard_timeout, :guard_timeout_exceeded, :sources_created, :pollables_created ].freeze
Class Method Summary collapse
-
.get(name, pollable_class, from: 1.hour.ago, to: Time.now) ⇒ ActiveRecord::Relation
Retrieves metric records.
-
.log(name, pollable_class) ⇒ Object
Logs a counter metric.
-
.log_value(name, pollable_class, value) ⇒ Object
Logs a value-based metric.
Class Method Details
.get(name, pollable_class, from: 1.hour.ago, to: Time.now) ⇒ ActiveRecord::Relation
Retrieves metric records.
72 73 74 75 76 77 78 |
# File 'lib/aeternitas/metrics.rb', line 72 def self.get(name, pollable_class, from: 1.hour.ago, to: Time.now) Aeternitas::Metric.where( name: name.to_s, pollable_class: pollable_class.name, created_at: from..to ).order(:created_at) end |
.log(name, pollable_class) ⇒ Object
Logs a counter metric. This creates a new metric record with a value of 1.
45 46 47 |
# File 'lib/aeternitas/metrics.rb', line 45 def self.log(name, pollable_class) log_value(name, pollable_class, 1) end |
.log_value(name, pollable_class, value) ⇒ Object
Logs a value-based metric.
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/aeternitas/metrics.rb', line 53 def self.log_value(name, pollable_class, value) return unless Aeternitas.config.metrics_enabled && AVAILABLE_METRICS.include?(name) Aeternitas::Metric.create( name: name.to_s, pollable_class: pollable_class.name, value: value, created_at: Time.now ) rescue # Metrics should fail silently end |