Class: Aikido::Zen::Collector::SinkStats Private
- Inherits:
-
Object
- Object
- Aikido::Zen::Collector::SinkStats
- Defined in:
- lib/aikido/zen/collector/sink_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 data specific to a single Sink.
Defined Under Namespace
Classes: CompressedTiming
Instance Attribute Summary collapse
-
#attacks ⇒ Integer
private
Number of scans where an attack was detected.
-
#blocked_attacks ⇒ Integer
private
Number of scans where an attack was detected and blocked by the Zen.
-
#compressed_timings ⇒ Array<CompressedTiming>
private
List of aggregated stats.
-
#errors ⇒ Integer
private
Number of scans where our scanners raised an error that was handled.
-
#scans ⇒ Integer
private
Number of total calls to Sink#scan.
-
#timings ⇒ Set<Float>
private
Keeps the duration of individual scans.
Instance Method Summary collapse
- #add_timing(duration) ⇒ Object private
- #as_json ⇒ Object private
- #compress_timings(at: Time.now.utc) ⇒ Object private
-
#initialize(name, config) ⇒ SinkStats
constructor
private
A new instance of SinkStats.
Constructor Details
#initialize(name, config) ⇒ SinkStats
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 SinkStats.
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/aikido/zen/collector/sink_stats.rb', line 32 def initialize(name, config) @name = name @config = config @scans = 0 @errors = 0 @attacks = 0 @blocked_attacks = 0 @timings = Set.new @compressed_timings = CappedSet.new(@config.max_compressed_stats) end |
Instance Attribute Details
#attacks ⇒ Integer
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 number of scans where an attack was detected.
18 19 20 |
# File 'lib/aikido/zen/collector/sink_stats.rb', line 18 def attacks @attacks end |
#blocked_attacks ⇒ Integer
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 number of scans where an attack was detected and blocked by the Zen.
22 23 24 |
# File 'lib/aikido/zen/collector/sink_stats.rb', line 22 def blocked_attacks @blocked_attacks end |
#compressed_timings ⇒ Array<CompressedTiming>
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 list of aggregated stats.
30 31 32 |
# File 'lib/aikido/zen/collector/sink_stats.rb', line 30 def compressed_timings @compressed_timings end |
#errors ⇒ Integer
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 number of scans where our scanners raised an error that was handled.
15 16 17 |
# File 'lib/aikido/zen/collector/sink_stats.rb', line 15 def errors @errors end |
#scans ⇒ Integer
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 number of total calls to Sink#scan.
11 12 13 |
# File 'lib/aikido/zen/collector/sink_stats.rb', line 11 def scans @scans end |
#timings ⇒ Set<Float>
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 keeps the duration of individual scans. If this grows to match Config#max_performance_samples, the set is cleared and the data is aggregated into #compressed_timings.
27 28 29 |
# File 'lib/aikido/zen/collector/sink_stats.rb', line 27 def timings @timings end |
Instance Method Details
#add_timing(duration) ⇒ 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.
46 47 48 49 |
# File 'lib/aikido/zen/collector/sink_stats.rb', line 46 def add_timing(duration) compress_timings if @timings.size >= @config.max_performance_samples @timings << duration 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.
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/aikido/zen/collector/sink_stats.rb', line 63 def as_json { total: @scans, interceptorThrewError: @errors, withoutContext: 0, attacksDetected: { total: @attacks, blocked: @blocked_attacks }, compressedTimings: @compressed_timings.as_json } end |
#compress_timings(at: Time.now.utc) ⇒ 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.
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/aikido/zen/collector/sink_stats.rb', line 51 def compress_timings(at: Time.now.utc) return if @timings.empty? list = @timings.sort @timings.clear mean = list.sum / list.size percentiles = percentiles(list, 50, 75, 90, 95, 99) @compressed_timings << CompressedTiming.new(mean, percentiles, at) end |