Class: Aikido::Zen::Collector::Stats Private
- Inherits:
-
Object
- Object
- Aikido::Zen::Collector::Stats
- Defined in:
- lib/aikido/zen/collector/stats.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Tracks information about how the Aikido Agent is used in the app.
Instance Method Summary collapse
- #add_attack(attack, being_blocked:) ⇒ self private
- #add_request ⇒ self private
- #add_scan(scan) ⇒ self private
- #any? ⇒ Boolean private
- #as_json ⇒ Object private
- #empty? ⇒ Boolean private
-
#flush(at: Time.now.utc) ⇒ self
private
Sets the end time for these stats block, freezes it to avoid any more writing to them, and compresses the timing stats in anticipation of sending these to the Aikido servers.
-
#initialize(config = Aikido::Zen.config) ⇒ Stats
constructor
private
A new instance of Stats.
-
#start(at = Time.now.utc) ⇒ self
private
Track the timestamp we start tracking this series of stats.
Constructor Details
#initialize(config = Aikido::Zen.config) ⇒ Stats
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.
Returns a new instance of Stats.
16 17 18 19 20 21 22 23 |
# File 'lib/aikido/zen/collector/stats.rb', line 16 def initialize(config = Aikido::Zen.config) super() @config = config @sinks = Hash.new { |h, k| h[k] = Collector::SinkStats.new(k, @config) } @started_at = @ended_at = nil @requests = 0 @aborted_requests = 0 end |
Instance Method Details
#add_attack(attack, being_blocked:) ⇒ self
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.
79 80 81 82 83 84 |
# File 'lib/aikido/zen/collector/stats.rb', line 79 def add_attack(attack, being_blocked:) stats = @sinks[attack.sink.name] stats.attacks += 1 stats.blocked_attacks += 1 if being_blocked self end |
#add_request ⇒ self
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.
60 61 62 63 |
# File 'lib/aikido/zen/collector/stats.rb', line 60 def add_request @requests += 1 self end |
#add_scan(scan) ⇒ self
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.
67 68 69 70 71 72 73 |
# File 'lib/aikido/zen/collector/stats.rb', line 67 def add_scan(scan) stats = @sinks[scan.sink.name] stats.scans += 1 stats.errors += 1 if scan.errors? stats.add_timing(scan.duration) self end |
#any? ⇒ 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.
31 32 33 |
# File 'lib/aikido/zen/collector/stats.rb', line 31 def any? !empty? end |
#as_json ⇒ 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.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/aikido/zen/collector/stats.rb', line 86 def as_json total_attacks, total_blocked = aggregate_attacks_from_sinks { startedAt: @started_at.to_i * 1000, endedAt: (@ended_at.to_i * 1000 if @ended_at), sinks: @sinks.transform_values(&:as_json), requests: { total: @requests, aborted: @aborted_requests, attacksDetected: { total: total_attacks, blocked: total_blocked } } } end |
#empty? ⇒ 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.
26 27 28 |
# File 'lib/aikido/zen/collector/stats.rb', line 26 def empty? @requests.zero? && @sinks.empty? end |
#flush(at: Time.now.utc) ⇒ self
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.
Sets the end time for these stats block, freezes it to avoid any more writing to them, and compresses the timing stats in anticipation of sending these to the Aikido servers.
51 52 53 54 55 56 57 |
# File 'lib/aikido/zen/collector/stats.rb', line 51 def flush(at: Time.now.utc) # Make sure the timing stats are compressed before copying, since we # need these compressed when we serialize this for the API. @sinks.each_value { |sink| sink.compress_timings(at: at) } @ended_at = at freeze end |
#start(at = Time.now.utc) ⇒ self
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.
Track the timestamp we start tracking this series of stats.
39 40 41 42 |
# File 'lib/aikido/zen/collector/stats.rb', line 39 def start(at = Time.now.utc) @started_at = at self end |