arkaan 1.6.1 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/arkaan/monitoring.rb +1 -0
- data/lib/arkaan/monitoring/instance.rb +2 -0
- data/lib/arkaan/monitoring/results.rb +10 -0
- data/lib/arkaan/monitoring/results/heartbeat.rb +50 -0
- data/lib/arkaan/monitoring/results/report.rb +46 -0
- data/lib/arkaan/monitoring/vigilante.rb +31 -0
- data/lib/arkaan/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bde2ac4f9badeeff70fa6534caafb6080a2d0d1f0f1a1a8166ad8b8607bb6bd7
|
4
|
+
data.tar.gz: 95b9406a7be27cf571956a25f15714e3738d23ce2f57bbf9d22ca4cdcaf41faa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd2894fdb157d26cbe7b1421566da14cb9f72ee9ca0033bd6e4c2c308f60985c1e09893f4040de08ec45642dae5b0cf36bb71fe1a2c5b83735d82c9354ce5dc7
|
7
|
+
data.tar.gz: fca967434233e4f426ed12a52de45892f555d03ea8288ed2184607ea8392dece9ab517c574996c30b6288b48c44b697dfca6642c2724b37e8013582482624f55
|
data/lib/arkaan/monitoring.rb
CHANGED
@@ -5,6 +5,7 @@ module Arkaan
|
|
5
5
|
autoload :Action , 'arkaan/monitoring/action'
|
6
6
|
autoload :Gateway , 'arkaan/monitoring/gateway'
|
7
7
|
autoload :Instance , 'arkaan/monitoring/instance'
|
8
|
+
autoload :Results , 'arkaan/monitoring/results'
|
8
9
|
autoload :Route , 'arkaan/monitoring/route'
|
9
10
|
autoload :Service , 'arkaan/monitoring/service'
|
10
11
|
autoload :Vigilante, 'arkaan/monitoring/vigilante'
|
@@ -27,6 +27,8 @@ module Arkaan
|
|
27
27
|
# @return [Arkaan::Monitoring::Action] the actions that has been performed on the service.
|
28
28
|
embeds_many :actions, class_name: 'Arkaan::Monitoring::Action', inverse_of: :instance
|
29
29
|
|
30
|
+
has_many :heartbeats, class_name: 'Arkaan::Monitoring::Results::Heartbeat', inverse_of: :instance
|
31
|
+
|
30
32
|
validates :url,
|
31
33
|
presence: {message: 'required'},
|
32
34
|
format: {with: /\A(https?:\/\/)((([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*)|(localhost:[0-9]{2,4})\/?)\z/, message: 'pattern', if: :url?}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Arkaan
|
2
|
+
module Monitoring
|
3
|
+
# The results module handle classes to make results for the vigilante runs.
|
4
|
+
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
5
|
+
module Results
|
6
|
+
autoload :Report, 'arkaan/monitoring/results/report'
|
7
|
+
autoload :Heartbeat, 'arkaan/monitoring/results/heartbeat'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Arkaan
|
2
|
+
module Monitoring
|
3
|
+
module Results
|
4
|
+
# A record is the result of the vigilante asking the health of one instance.
|
5
|
+
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
6
|
+
class Heartbeat
|
7
|
+
include Mongoid::Document
|
8
|
+
|
9
|
+
# @!attribute [rw] status
|
10
|
+
# @return [Integer] the HTTP status of the request made for this record.
|
11
|
+
field :status, type: Integer, default: 500
|
12
|
+
# @!attribute [rw] body
|
13
|
+
# @return [Hash] the JSON parsed body from the heartbeat request.
|
14
|
+
field :body, type: Hash, default: {}
|
15
|
+
# @!attribute [rw] healthy
|
16
|
+
# @return [Boolean] TRUE if the instance is deemed healthy, FALSE otherwise.
|
17
|
+
field :healthy, type: Boolean, default: false
|
18
|
+
# @!attribute [rw] started_at
|
19
|
+
# @return [DateTime] the date at which the heartbeat request has started.
|
20
|
+
field :started_at, type: DateTime
|
21
|
+
# @!attribute [rw] ended_at
|
22
|
+
# @return [DateTime] the date at which the request was terminated.
|
23
|
+
field :ended_at, type: DateTime
|
24
|
+
|
25
|
+
# @!attribute [rw] instance
|
26
|
+
# @return [Arkaan::Monitoring::Instance] the instance on which the record has been done.
|
27
|
+
belongs_to :instance, class_name: 'Arkaan::Monitoring::Instance', inverse_of: :heartbeats
|
28
|
+
|
29
|
+
# @!attribute [rw] report
|
30
|
+
# @return [Arkaan::Monitoring::Results::Report] the report made by the vigilante including this record.
|
31
|
+
belongs_to :report, class_name: 'Arkaan::Monitoring::Results::Report', inverse_of: :heartbeats
|
32
|
+
|
33
|
+
attr_readonly :healthy
|
34
|
+
|
35
|
+
def status=(status)
|
36
|
+
self[:status] = status
|
37
|
+
self[:healthy] = status == 200
|
38
|
+
end
|
39
|
+
|
40
|
+
def start!
|
41
|
+
self.started_at = DateTime.now
|
42
|
+
end
|
43
|
+
|
44
|
+
def end!
|
45
|
+
self.ended_at = DateTime.now
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Arkaan
|
2
|
+
module Monitoring
|
3
|
+
module Results
|
4
|
+
# A report is the result of one call to the API on one instance status route.
|
5
|
+
# @author Vincent Courtois <courtoi.vincent@outlook.com>
|
6
|
+
class Report
|
7
|
+
include Mongoid::Document
|
8
|
+
include Mongoid::Timestamps
|
9
|
+
|
10
|
+
field :started_at, type: DateTime
|
11
|
+
# @!attribute [rw] ended_at
|
12
|
+
# @return [DateTime] the timestamp at which the report ends.
|
13
|
+
field :ended_at, type: DateTime
|
14
|
+
# @!attribute [rw] total
|
15
|
+
# @return [Integer] the total number of services monitored.
|
16
|
+
field :total, type: Integer, default: 0
|
17
|
+
# @!attribute [rw] healthy
|
18
|
+
# @return [Integer] the number of healthy services amongst all the monitored services.
|
19
|
+
field :healthy, type: Integer, default: 0
|
20
|
+
|
21
|
+
# @!attribute [rw] records
|
22
|
+
# @return [Array<Arkaan::Monitoring::Results::Record>] the records linked to this report.
|
23
|
+
has_many :heartbeats, class_name: 'Arkaan::Monitoring::Results::Heartbeat', inverse_of: :report
|
24
|
+
# @!attribute [rw] vigilante
|
25
|
+
# @return [Arkaan::Monitoring::Vigilante] the vigilante application that has created this report.
|
26
|
+
belongs_to :vigilante, class_name: 'Arkaan::Monitoring::Vigilante', inverse_of: :reports
|
27
|
+
|
28
|
+
def add_heartbeat(heartbeat)
|
29
|
+
self.heartbeats << heartbeat
|
30
|
+
self.total += 1
|
31
|
+
self.healthy += (heartbeat.healthy ? 1 : 0)
|
32
|
+
heartbeat.end!
|
33
|
+
end
|
34
|
+
|
35
|
+
def start!
|
36
|
+
self.started_at = DateTime.now
|
37
|
+
end
|
38
|
+
|
39
|
+
def end!
|
40
|
+
self.ended_at = DateTime.now
|
41
|
+
self.save!
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -10,8 +10,39 @@ module Arkaan
|
|
10
10
|
# @!attribute [rw] token
|
11
11
|
# @return [String] the token the vigilante uses to identify himself in the services
|
12
12
|
field :token, type: String
|
13
|
+
# @!attribute [rw] max_results
|
14
|
+
# @return [Integer] the number of results the vigilante should be keeping at any time.
|
15
|
+
# The oldest result should be erased to not go over the limit
|
16
|
+
field :max_results, type: Integer, default: 20
|
17
|
+
|
18
|
+
# @!attribute [rw] reports
|
19
|
+
# @return [Array<Arkaan::monitoring::Results::Report>] the report generated by running this vigilante.
|
20
|
+
has_many :reports, class_name: 'Arkaan::Monitoring::Results::Report', inverse_of: :vigilante
|
13
21
|
|
14
22
|
validates :token, presence: {message: 'required'}
|
23
|
+
|
24
|
+
validates :max_results,
|
25
|
+
numericality: {greater_than: 0, message: 'minimum'}
|
26
|
+
|
27
|
+
# Adds a report to the collection of reports by eventually deleting the oldest one.
|
28
|
+
# @param report [Arkaan::Monitoring::Results::Report] the report to add to the vigilante,
|
29
|
+
# added only if it does not exceed the max number of reports the vigilante can store.
|
30
|
+
def add_report(report)
|
31
|
+
erase_oldest_result if result_full?
|
32
|
+
reports << report
|
33
|
+
end
|
34
|
+
|
35
|
+
# Checks if the list of reports is already full, or if more can be added.
|
36
|
+
# @return [Boolean] TRUE if the number of reports already exceeds the max number.
|
37
|
+
def results_full?
|
38
|
+
reports.to_a.count >= max_results
|
39
|
+
end
|
40
|
+
|
41
|
+
# Erases the oldest results to keep only MAX - 1 results in the list.
|
42
|
+
def erase_oldest_result
|
43
|
+
limit = reports.count + 1 - vigilante.max_results
|
44
|
+
reports.sort_by(created_at: :asc).limit(limit).each(&:delete)
|
45
|
+
end
|
15
46
|
end
|
16
47
|
end
|
17
48
|
end
|
data/lib/arkaan/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arkaan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vincent Courtois
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -330,6 +330,9 @@ files:
|
|
330
330
|
- lib/arkaan/monitoring/action.rb
|
331
331
|
- lib/arkaan/monitoring/gateway.rb
|
332
332
|
- lib/arkaan/monitoring/instance.rb
|
333
|
+
- lib/arkaan/monitoring/results.rb
|
334
|
+
- lib/arkaan/monitoring/results/heartbeat.rb
|
335
|
+
- lib/arkaan/monitoring/results/report.rb
|
333
336
|
- lib/arkaan/monitoring/route.rb
|
334
337
|
- lib/arkaan/monitoring/service.rb
|
335
338
|
- lib/arkaan/monitoring/vigilante.rb
|