Class: LogStashAutoResizeBuffer
- Inherits:
-
Object
- Object
- LogStashAutoResizeBuffer
- Includes:
- Stud::Buffer
- Defined in:
- lib/logstash/logAnalyticsClient/logStashAutoResizeBuffer.rb
Overview
LogStashAutoResizeBuffer class setting a resizable buffer which is flushed periodically The buffer resize itself according to Azure Loganalytics and configuration limitations
Instance Method Summary collapse
-
#add_event_document(event_document) ⇒ Object
Adding an event document into the buffer.
-
#flush(documents, close = false) ⇒ Object
Flushing all buffer content to Azure Loganalytics.
-
#initialize(logstashLoganalyticsConfiguration) ⇒ LogStashAutoResizeBuffer
constructor
A new instance of LogStashAutoResizeBuffer.
Constructor Details
#initialize(logstashLoganalyticsConfiguration) ⇒ LogStashAutoResizeBuffer
Returns a new instance of LogStashAutoResizeBuffer.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/logstash/logAnalyticsClient/logStashAutoResizeBuffer.rb', line 12 def initialize(logstashLoganalyticsConfiguration) @logstashLoganalyticsConfiguration = logstashLoganalyticsConfiguration @logger = @logstashLoganalyticsConfiguration.logger @client=LogAnalyticsClient::new(logstashLoganalyticsConfiguration) buffer_initialize( :max_items => logstashLoganalyticsConfiguration.max_items, :max_interval => logstashLoganalyticsConfiguration.plugin_flush_interval, :logger => @logstashLoganalyticsConfiguration.logger ) end |
Instance Method Details
#add_event_document(event_document) ⇒ Object
Adding an event document into the buffer
27 28 29 |
# File 'lib/logstash/logAnalyticsClient/logStashAutoResizeBuffer.rb', line 27 def add_event_document(event_document) buffer_receive(event_document) end |
#flush(documents, close = false) ⇒ Object
Flushing all buffer content to Azure Loganalytics. Called from Stud::Buffer#buffer_flush when there are events to flush
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/logstash/logAnalyticsClient/logStashAutoResizeBuffer.rb', line 33 def flush (documents, close=false) # Skip in case there are no candidate documents to deliver if documents.length < 1 @logger.warn("No documents in batch for log type #{@logstashLoganalyticsConfiguration.custom_log_table_name}. Skipping") return end # We send Json in the REST request documents_json = documents.to_json # Setting resizing to true will cause changing the max size if @logstashLoganalyticsConfiguration.amount_resizing == true # Resizing the amount of messages according to size of message received and amount of messages (documents.length, documents_json.bytesize) end (documents_json, documents.length) end |