Class: Utility

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/utility.rb

Class Method Summary collapse

Class Method Details

.compress_payload(payload) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/fluent/plugin/utility.rb', line 4

def self.compress_payload(payload)
    puts "#{self.get_time} Compressing metrics payload"
    json_payload = payload.to_json

    # Compress the JSON string using zlib's GzipWriter
    compressed_payload = StringIO.new    
    Zlib::GzipWriter.wrap(compressed_payload) do |gz|
      gz.write(json_payload)
    end

    # convert the compressed data to a string
    compressed_data = compressed_payload.string

    puts "#{self.get_time} Original metrics payload size: #{json_payload.bytesize} bytes"
    puts "#{self.get_time} Compressed metrics payload size: #{compressed_data.bytesize} bytes"

    return compressed_data
end

.get_timeObject



23
24
25
# File 'lib/fluent/plugin/utility.rb', line 23

def self.get_time() 
    return Time.now.strftime("%Y-%m-%d %H:%M:%S")
end