Class: Arkaan::Monitoring::Vigilante

Inherits:
Object
  • Object
show all
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.

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#max_resultsInteger

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.

Returns:

  • (Integer)

    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

#reportsArray<Arkaan::monitoring::Results::Report>

Returns the report generated by running this vigilante.

Returns:

  • (Array<Arkaan::monitoring::Results::Report>)

    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

#tokenString

Returns the token the vigilante uses to identify himself in the services.

Returns:

  • (String)

    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.

Parameters:



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_resultObject

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.

Returns:

  • (Boolean)

    TRUE if the number of reports already exceeds the max number.



37
38
39
# File 'lib/arkaan/monitoring/vigilante.rb', line 37

def results_full?
  reports.to_a.count >= max_results
end