Class: LogStash::Outputs::Cls

Inherits:
Base
  • Object
show all
Includes:
Stud::Buffer
Defined in:
lib/logstash/outputs/cls.rb

Constant Summary collapse

LP =
com.tencentcloudapi.cls.producer
LogCommon =
com.tencentcloudapi.cls.producer.common

Instance Method Summary collapse

Instance Method Details

#closeObject



101
102
103
# File 'lib/logstash/outputs/cls.rb', line 101

def close
  @producer.close();
end

#flush(events, close = false) ⇒ Object

def event



97
98
# File 'lib/logstash/outputs/cls.rb', line 97

def flush(events, close=false)
end

#receive(event) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/logstash/outputs/cls.rb', line 64

def receive(event)
begin
  @event_map = event.to_hash
  if @event_map.size < 1
    return
  end
  @logitem = LogCommon.LogItem.new
  #@timestamp like 2016-02-18T03:23:11.053Z
  time_value = @event_map[@time_key]
  if time_value.nil?
     time_value = @event_map['@timestamp']
     @logger.warn("The time_key is nil, use @timestamp")
  end
  @logitem.SetTime(Time.parse(time_value.to_s).to_datetime().strftime('%Q').to_i)
  @event_map.each do | key, value |
    @key_str = key.to_s
    if @key_str == '__time__'
      next
    end
    if value.instance_of? Hash
      @value_str = value.to_json
    else
      @value_str = value.to_s
    end
    @logitem.PushBack(@key_str, @value_str)
  end

  @producer.putLog(@topic_id, @logitem)
  rescue => e
    @logger.warn("send log data fail", :exception => e)
  end
end

#registerObject



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/logstash/outputs/cls.rb', line 50

def register
  @producerConfig = LP.AsyncProducerConfig::new(@endpoint, @access_key_id, @access_key_secret, @source);
  @producerConfig.setBatchCountThreshold(@max_buffer_items);
  @producerConfig.setBatchSizeThresholdInBytes(@max_buffer_bytes);
  @producerConfig.setLingerMs(@max_buffer_seconds*1000);
  @producerConfig.setRetries(@max_send_retry);
  @producerConfig.setBaseRetryBackoffMs(@send_retry_interval);
  @producerConfig.setTotalSizeInBytes(@total_size_in_bytes);
  @producer = LP.AsyncProducerClient::new(@producerConfig);

  @logger.info("init logstash-output-cls plugin", :endpoint => @endpoint, :topic_id => @topic_id, :source => @source, :max_buffer_bytes => @max_buffer_bytes)
end