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.
- #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 request, 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
Returns a new instance of Collector.
7 8 9 10 11 12 13 14 |
# 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)) 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.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/aikido/zen/collector.rb', line 22 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) 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.
97 98 99 |
# File 'lib/aikido/zen/collector.rb', line 97 def hosts @hosts.get 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.
87 88 89 |
# File 'lib/aikido/zen/collector.rb', line 87 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.
38 39 40 |
# File 'lib/aikido/zen/collector.rb', line 38 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.
102 103 104 |
# File 'lib/aikido/zen/collector.rb', line 102 def stats @stats.get end |
#track_attack(attack) ⇒ void
This method returns an undefined value.
Track stats about an attack detected by our scanners.
64 65 66 67 68 |
# File 'lib/aikido/zen/collector.rb', line 64 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.
74 75 76 |
# File 'lib/aikido/zen/collector.rb', line 74 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 request, record the visited endpoint, and if enabled, the API schema for this endpoint.
47 48 49 50 |
# File 'lib/aikido/zen/collector.rb', line 47 def track_request(request) synchronize(@stats) { |stats| stats.add_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.
56 57 58 |
# File 'lib/aikido/zen/collector.rb', line 56 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.
82 83 84 |
# File 'lib/aikido/zen/collector.rb', line 82 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.
92 93 94 |
# File 'lib/aikido/zen/collector.rb', line 92 def users @users.get end |