Class: Aikido::Zen::Collector
- Inherits:
-
Object
- Object
- Aikido::Zen::Collector
- Defined in:
- lib/aikido/zen/collector.rb
Overview
Handles collecting all the runtime statistics to report back to the Aikido servers.
Defined Under Namespace
Classes: Hosts, Routes, SinkStats, Stats, Users
Instance Method Summary collapse
-
#flush(at: Time.now.utc) ⇒ Aikido::Zen::Events::Heartbeat
Flush all the stats into a Heartbeat event that can be reported back to the Aikido servers.
- #hosts ⇒ Object private
-
#initialize(config: Aikido::Zen.config) ⇒ Collector
constructor
A new instance of Collector.
- #middleware_installed! ⇒ Object
- #middleware_installed? ⇒ Boolean private
- #routes ⇒ Object private
-
#start(at: Time.now.utc) ⇒ void
Sets the start time for this collection period.
- #stats ⇒ Object private
-
#track_attack(attack) ⇒ void
Track stats about an attack detected by our scanners.
-
#track_outbound(connection) ⇒ void
Track an HTTP connections to an external host.
-
#track_request(request) ⇒ void
Track stats about the requests.
-
#track_route(request) ⇒ Object
Record the visited endpoint, and if enabled, the API schema for this endpoint.
-
#track_scan(scan) ⇒ void
Track stats about a scan performed by one of our sinks.
-
#track_user(actor) ⇒ void
Track the user reported by the developer to be behind this request.
- #users ⇒ Object private
Constructor Details
#initialize(config: Aikido::Zen.config) ⇒ Collector
7 8 9 10 11 12 13 14 15 |
# File 'lib/aikido/zen/collector.rb', line 7 def initialize(config: Aikido::Zen.config) @config = config @stats = Concurrent::AtomicReference.new(Stats.new(@config)) @users = Concurrent::AtomicReference.new(Users.new(@config)) @hosts = Concurrent::AtomicReference.new(Hosts.new(@config)) @routes = Concurrent::AtomicReference.new(Routes.new(@config)) @middleware_installed = Concurrent::AtomicBoolean.new end |
Instance Method Details
#flush(at: Time.now.utc) ⇒ Aikido::Zen::Events::Heartbeat
Flush all the stats into a Heartbeat event that can be reported back to the Aikido servers.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/aikido/zen/collector.rb', line 23 def flush(at: Time.now.utc) stats = @stats.get_and_set(Stats.new(@config)) users = @users.get_and_set(Users.new(@config)) hosts = @hosts.get_and_set(Hosts.new(@config)) routes = @routes.get_and_set(Routes.new(@config)) start(at: at) stats = stats.flush(at: at) Events::Heartbeat.new( stats: stats, users: users, hosts: hosts, routes: routes, middleware_installed: middleware_installed? ) end |
#hosts ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
108 109 110 |
# File 'lib/aikido/zen/collector.rb', line 108 def hosts @hosts.get end |
#middleware_installed! ⇒ Object
93 94 95 |
# File 'lib/aikido/zen/collector.rb', line 93 def middleware_installed! @middleware_installed.make_true end |
#middleware_installed? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
118 119 120 |
# File 'lib/aikido/zen/collector.rb', line 118 def middleware_installed? @middleware_installed.true? end |
#routes ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
98 99 100 |
# File 'lib/aikido/zen/collector.rb', line 98 def routes @routes.get end |
#start(at: Time.now.utc) ⇒ void
This method returns an undefined value.
Sets the start time for this collection period.
41 42 43 |
# File 'lib/aikido/zen/collector.rb', line 41 def start(at: Time.now.utc) synchronize(@stats) { |stats| stats.start(at) } end |
#stats ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
113 114 115 |
# File 'lib/aikido/zen/collector.rb', line 113 def stats @stats.get end |
#track_attack(attack) ⇒ void
This method returns an undefined value.
Track stats about an attack detected by our scanners.
71 72 73 74 75 |
# File 'lib/aikido/zen/collector.rb', line 71 def track_attack(attack) synchronize(@stats) do |stats| stats.add_attack(attack, being_blocked: attack.blocked?) end end |
#track_outbound(connection) ⇒ void
This method returns an undefined value.
Track an HTTP connections to an external host.
81 82 83 |
# File 'lib/aikido/zen/collector.rb', line 81 def track_outbound(connection) synchronize(@hosts) { |hosts| hosts.add(connection) } end |
#track_request(request) ⇒ void
This method returns an undefined value.
Track stats about the requests
49 50 51 |
# File 'lib/aikido/zen/collector.rb', line 49 def track_request(request) synchronize(@stats) { |stats| stats.add_request } end |
#track_route(request) ⇒ Object
Record the visited endpoint, and if enabled, the API schema for this endpoint.
55 56 57 |
# File 'lib/aikido/zen/collector.rb', line 55 def track_route(request) synchronize(@routes) { |routes| routes.add(request) if request.route } end |
#track_scan(scan) ⇒ void
This method returns an undefined value.
Track stats about a scan performed by one of our sinks.
63 64 65 |
# File 'lib/aikido/zen/collector.rb', line 63 def track_scan(scan) synchronize(@stats) { |stats| stats.add_scan(scan) } end |
#track_user(actor) ⇒ void
This method returns an undefined value.
Track the user reported by the developer to be behind this request.
89 90 91 |
# File 'lib/aikido/zen/collector.rb', line 89 def track_user(actor) synchronize(@users) { |users| users.add(actor) } end |
#users ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
103 104 105 |
# File 'lib/aikido/zen/collector.rb', line 103 def users @users.get end |