Class: Fluent::Plugin::BeaconOutput
- Inherits:
-
Output
- Object
- Output
- Fluent::Plugin::BeaconOutput
- Defined in:
- lib/fluent/plugin/out_f5_beacon.rb
Constant Summary collapse
- DEFAULT_BUFFER_TYPE =
"memory"
- FORMATTED_RESULT_FOR_INVALID_RECORD =
''.freeze
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #create_request(payload) ⇒ Object
- #format(tag, time, record) ⇒ Object
- #formatted_to_msgpack_binary ⇒ Object
- #handle_payload(payload) ⇒ Object
-
#http_opts(uri) ⇒ Object
end send_request.
-
#initialize ⇒ BeaconOutput
constructor
A new instance of BeaconOutput.
- #multi_workers_ready? ⇒ Boolean
- #precision_time(time) ⇒ Object
- #send_request(req, uri) ⇒ Object
- #serialize(points) ⇒ Object
- #shutdown ⇒ Object
- #start ⇒ Object
- #write(chunk) ⇒ Object
- #write_points(points) ⇒ Object
Constructor Details
#initialize ⇒ BeaconOutput
Returns a new instance of BeaconOutput.
57 58 59 60 61 |
# File 'lib/fluent/plugin/out_f5_beacon.rb', line 57 def initialize super @seq = 0 @prev_timestamp = nil end |
Instance Method Details
#configure(conf) ⇒ Object
63 64 65 66 67 |
# File 'lib/fluent/plugin/out_f5_beacon.rb', line 63 def configure(conf) compat_parameters_convert(conf, :buffer) super raise Fluent::ConfigError, "'tag' in chunk_keys is required." if not @chunk_key_tag end |
#create_request(payload) ⇒ Object
191 192 193 194 195 196 197 198 199 200 |
# File 'lib/fluent/plugin/out_f5_beacon.rb', line 191 def create_request(payload) uri = URI.parse(@endpoint) req = Net::HTTP.const_get("Post").new(uri.request_uri) req['X-F5-Ingestion-Token'] = @token req['Content-Type'] = 'text/plain' req.body = payload return req, uri end |
#format(tag, time, record) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/fluent/plugin/out_f5_beacon.rb', line 76 def format(tag, time, record) # Remove nil/empty values record.delete_if { |k, v| v.nil? || v.to_s.empty? } if record.empty? log.warn "skip record '#{record}' in '#{tag}', because record has no values" FORMATTED_RESULT_FOR_INVALID_RECORD else [precision_time(time), record].to_msgpack end end |
#formatted_to_msgpack_binary ⇒ Object
92 93 94 |
# File 'lib/fluent/plugin/out_f5_beacon.rb', line 92 def formatted_to_msgpack_binary true end |
#handle_payload(payload) ⇒ Object
186 187 188 189 |
# File 'lib/fluent/plugin/out_f5_beacon.rb', line 186 def handle_payload(payload) req, uri = create_request(payload) send_request(req, uri) end |
#http_opts(uri) ⇒ Object
end send_request
224 225 226 227 228 229 230 231 232 |
# File 'lib/fluent/plugin/out_f5_beacon.rb', line 224 def http_opts(uri) opts = { :use_ssl => true, :verify_mode => OpenSSL::SSL::VERIFY_PEER, :ssl_version => :TLSv1_2, :ciphers => ['AES128-GCM-SHA256', 'AES128-SHA256', 'AES256-GCM-SHA384', 'AES256-SHA256', 'ECDHE-RSA-AES128-GCM-SHA256', 'ECDHE-RSA-AES128-SHA256', 'ECDHE-RSA-AES256-GCM-SHA384', 'ECDHE-RSA-AES256-SHA384'], } opts end |
#multi_workers_ready? ⇒ Boolean
96 97 98 |
# File 'lib/fluent/plugin/out_f5_beacon.rb', line 96 def multi_workers_ready? true end |
#precision_time(time) ⇒ Object
181 182 183 184 |
# File 'lib/fluent/plugin/out_f5_beacon.rb', line 181 def precision_time(time) # nsec is supported from v0.14 time * (10 ** 9) + (time.is_a?(Integer) ? 0 : time.nsec) end |
#send_request(req, uri) ⇒ Object
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/fluent/plugin/out_f5_beacon.rb', line 202 def send_request(req, uri) res = nil begin res = Net::HTTP.start(uri.host, uri.port, **http_opts(uri)) {|http| http.request(req) } rescue => e # rescue all StandardErrors # server didn't respond log.warn "Net::HTTP.#{req.method.capitalize} raises exception: #{e.class}, '#{e.}'" raise e else unless res and res.is_a?(Net::HTTPSuccess) res_summary = if res "#{res.code} #{res.} #{res.body}" else "res=nil" end log.warn "failed to #{req.method} #{uri} (#{res_summary})" end #end unless end # end begin end |
#serialize(points) ⇒ Object
175 176 177 178 179 |
# File 'lib/fluent/plugin/out_f5_beacon.rb', line 175 def serialize(points) points.map do |point| InfluxDB::PointValue.new(point).dump end.join("\n".freeze) end |
#shutdown ⇒ Object
88 89 90 |
# File 'lib/fluent/plugin/out_f5_beacon.rb', line 88 def shutdown super end |
#start ⇒ Object
69 70 71 72 |
# File 'lib/fluent/plugin/out_f5_beacon.rb', line 69 def start super log.info "starting F5 Beacon plugin..." end |
#write(chunk) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/fluent/plugin/out_f5_beacon.rb', line 100 def write(chunk) points = [] tag = chunk..tag chunk.msgpack_each do |time, record| = record.delete(@time_key) || time if tag_keys.empty? && !@auto_tags values = record = {} else values = {} = {} record.each_pair do |k, v| if (@auto_tags && v.is_a?(String)) || @tag_keys.include?(k) # If the tag value is not nil, empty, or a space, add the tag normalized_value = v.to_s.strip if normalized_value != '' [k] = normalized_value end else values[k] = v end end end if @sequence_tag if @prev_timestamp == @seq += 1 else @seq = 0 end [@sequence_tag] = @seq @prev_timestamp = end values.delete_if do |k, v| if v.is_a?(Array) || v.is_a?(Hash) log.warn "array/hash field '#{k}' discarded; consider using a plugin to map" true end end if values.empty? log.warn "skip record '#{record}', because one value is required" next end if @cast_number_to_float values.each do |key, value| if value.is_a?(Integer) values[key] = Float(value) end end end ["beacon-fluent-source"] = @source_name point = { timestamp: , series: @measurement || tag, values: values, tags: , } points << point end if points.length > 0 write_points(points) end end |
#write_points(points) ⇒ Object
170 171 172 173 |
# File 'lib/fluent/plugin/out_f5_beacon.rb', line 170 def write_points(points) payload = serialize(points) handle_payload(payload) end |