Class: Arkaan::Monitoring::Vigilante
- Inherits:
-
Object
- Object
- Arkaan::Monitoring::Vigilante
- Includes:
- Mongoid::Document, Mongoid::Timestamps
- Defined in:
- lib/arkaan/monitoring/vigilante.rb
Overview
A vigilante is a specific type of service that watches over the infrastructure and give a clear look at its global state.
Instance Attribute Summary collapse
-
#max_results ⇒ Integer
The number of results the vigilante should be keeping at any time.
-
#reports ⇒ Array<Arkaan::monitoring::Results::Report>
The report generated by running this vigilante.
-
#token ⇒ String
The token the vigilante uses to identify himself in the services.
Instance Method Summary collapse
-
#add_report(report) ⇒ Object
Adds a report to the collection of reports by eventually deleting the oldest one.
-
#erase_oldest_result ⇒ Object
Erases the oldest results to keep only MAX - 1 results in the list.
-
#results_full? ⇒ Boolean
Checks if the list of reports is already full, or if more can be added.
Instance Attribute Details
#max_results ⇒ Integer
Returns the number of results the vigilante should be keeping at any time. The oldest result should be erased to not go over the limit.
16 |
# File 'lib/arkaan/monitoring/vigilante.rb', line 16 field :max_results, type: Integer, default: 20 |
#reports ⇒ Array<Arkaan::monitoring::Results::Report>
Returns the report generated by running this vigilante.
20 |
# File 'lib/arkaan/monitoring/vigilante.rb', line 20 has_many :reports, class_name: 'Arkaan::Monitoring::Results::Report', inverse_of: :vigilante |
#token ⇒ String
Returns the token the vigilante uses to identify himself in the services.
12 |
# File 'lib/arkaan/monitoring/vigilante.rb', line 12 field :token, type: String |
Instance Method Details
#add_report(report) ⇒ Object
Adds a report to the collection of reports by eventually deleting the oldest one.
30 31 32 33 |
# File 'lib/arkaan/monitoring/vigilante.rb', line 30 def add_report(report) erase_oldest_result if result_full? reports << report end |
#erase_oldest_result ⇒ Object
Erases the oldest results to keep only MAX - 1 results in the list.
42 43 44 45 |
# File 'lib/arkaan/monitoring/vigilante.rb', line 42 def erase_oldest_result limit = reports.count + 1 - vigilante.max_results reports.sort_by(created_at: :asc).limit(limit).each(&:delete) end |
#results_full? ⇒ Boolean
Checks if the list of reports is already full, or if more can be added.
37 38 39 |
# File 'lib/arkaan/monitoring/vigilante.rb', line 37 def results_full? reports.to_a.count >= max_results end |