fluent-plugin-archagent 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 546c5a6ad8db55c14e830f9630cfe690b243409b
4
- data.tar.gz: ef30d7d2bcfdc913d03b08d13e21df16ffe8b81d
3
+ metadata.gz: efe242f9fe55889fff7c4a4619eddab44fd67c68
4
+ data.tar.gz: 54eceb112086c82ee1e2573fc8b6671a5a27f998
5
5
  SHA512:
6
- metadata.gz: 271fd165b1236a7758c11a11176dab8e607c3da08b7803f7052280ee5f19d57fe8b1573c361b7747529d971c3971c1f71e8d842ab544edc39cd05412b5aa1bb1
7
- data.tar.gz: 2e26fa7cb03296cb0d951a90604ca162310e04cbcd31277f5704f021814a2f74599dca04df5d3ae50984a29d6d91a62bca2372da66b7759903785371d87318bf
6
+ metadata.gz: f0757c57125978ac63c69b2aedbbdb9c8d086adb92a5e24d5251895797c5e74997c5fcdbf3bfae90fdb0e11df9adfb4459ed6bf5c1d63c2d56fa92505abb9a38
7
+ data.tar.gz: f0d14d6fe705683579f025d12787635d7758aed6279e13f322e050c86ea957f42e46057d422636fa8180ba31c8bec9380f59a1ee5e2c440eaca5460e600deb84
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = "fluent-plugin-archagent"
6
- spec.version = "0.1.1"
6
+ spec.version = "0.1.2"
7
7
  spec.authors = ["apoorv"]
8
8
  spec.email = ["apoorv@archsaber.com"]
9
9
 
@@ -1,93 +1,91 @@
1
1
  module Fluent::Plugin
2
- class ArchagentOutput < Fluent::BufferedOutput
3
- Fluent::Plugin.register_output("archagent", self)
2
+ class ArchagentOutput < Fluent::BufferedOutput
3
+ Fluent::Plugin.register_output("archagent", self)
4
4
 
5
- def initialize
6
- super
7
- require 'net/http'
8
- require 'uri'
9
- end
5
+ def initialize
6
+ super
7
+ require 'net/http'
8
+ require 'uri'
9
+ end
10
10
 
11
- # Archagent port for listening to logs from apache. This should be same as the one specified
11
+ # Archagent port for listening to logs from apache. This should be same as the one specified
12
12
  # in data.json for archagent
13
- config_param :port, :string, default: '8018'
13
+ config_param :port, :string, default: '8118'
14
14
 
15
- # read timeout for the http call
16
- config_param :http_read_timeout, :float, default: 2.0
15
+ def configure(conf)
16
+ super
17
17
 
18
- # open timeout for the http call
19
- config_param :http_open_timeout, :float, default: 2.0
18
+ endpoint_url = 'http://localhost:' + @port
19
+ # Check if endpoint URL is valid
20
+ unless endpoint_url =~ /^#{URI.regexp}$/
21
+ fail Fluent::ConfigError, 'port invalid'
22
+ end
20
23
 
21
- def configure(conf)
22
- super
24
+ begin
25
+ @uri = URI.parse(endpoint_url)
26
+ rescue URI::InvalidURIError
27
+ raise Fluent::ConfigError, 'port invalid'
28
+ end
29
+ end
23
30
 
24
- endpoint_url = 'http://localhost:' + @port
25
- # Check if endpoint URL is valid
26
- unless endpoint_url =~ /^#{URI.regexp}$/
27
- fail Fluent::ConfigError, 'port invalid'
31
+ def format(tag, time, record)
32
+ [tag, time, record].to_msgpack
28
33
  end
29
34
 
30
- begin
31
- @uri = URI.parse(endpoint_url)
32
- rescue URI::InvalidURIError
33
- raise Fluent::ConfigError, 'port invalid'
35
+ def start
36
+ super
34
37
  end
35
38
 
36
- @http = Net::HTTP.new(@uri.host, @uri.port)
37
- @http.read_timeout = @http_read_timeout
38
- @http.open_timeout = @http_open_timeout
39
- end
39
+ def shutdown
40
+ super
40
41
 
41
- def format(tag, time, record)
42
- [tag, time, record].to_msgpack
43
- end
42
+ disconnect
43
+ end
44
44
 
45
- def start
46
- super
47
- end
45
+ def write(chunk)
46
+ log_data = []
47
+ chunk.msgpack_each do |(tag, time, record)|
48
+ record['host'] = (record.has_key? 'host') && record['host'] != nil && record['host'] != "" ? \
49
+ record['host'].to_s : 'unknown'
50
+ record['code'] = (record.has_key? 'code') && record['code'] != nil && record['code'] != "" ? \
51
+ record['code'].to_i : -1
52
+ record['size'] = (record.has_key? 'size') && record['size'] != nil && record['size'] != "" ? \
53
+ record['size'].to_i : -1
54
+ record['latency'] = (record.has_key? 'latency') && record['latency'] != nil && \
55
+ record['latency'] != "" ? record['latency'].to_i : -1
56
+ log_data << record
57
+ end
48
58
 
49
- def shutdown
50
- super
51
- begin
52
- @http.finish
53
- rescue
59
+ log_data_req = create_request(log_data)
60
+ response = connect.request(log_data_req)
61
+ return
54
62
  end
55
- end
56
63
 
57
- def write(chunk)
58
- data = []
59
- chunk.msgpack_each do |(tag, time, record)|
60
- data << record
64
+ def connect
65
+ @http ||= Net::HTTP.start(
66
+ @uri.host,
67
+ @uri.port,
68
+ keep_alive_timeout: 60.0
69
+ )
61
70
  end
62
- request = create_request(data)
63
71
 
64
- begin
65
- response = @http.start do |http|
66
- request = create_request(data)
67
- http.request request
68
- end
69
- rescue IOError, EOFError, SystemCallError => e
70
- # server didn't respond
71
- $log.warn "Net::HTTP.#{request.method.capitalize} raises exception: #{e.class}, '#{e.message}'"
72
- ensure
73
- begin
74
- @http.finish
75
- rescue
76
- end
72
+ def disconnect
73
+ return unless defined?(@http)
74
+ return unless @http
75
+ @http.finish
77
76
  end
78
- end
79
77
 
80
- protected
78
+ protected
81
79
 
82
- def create_request(data)
83
- request = Net::HTTP::Post.new(@uri.request_uri)
80
+ def create_request(data)
81
+ request = Net::HTTP::Post.new(@uri.request_uri)
84
82
 
85
- # Headers
86
- request['Content-Type'] = 'application/json'
83
+ # Headers
84
+ request['Content-Type'] = 'application/json'
87
85
 
88
- # Body
89
- request.body = JSON.dump(data)
90
- request
86
+ # Body
87
+ request.body = JSON.dump(data)
88
+ request
89
+ end
91
90
  end
92
- end
93
91
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-archagent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - apoorv
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-07 00:00:00.000000000 Z
11
+ date: 2018-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -83,7 +83,6 @@ files:
83
83
  - LICENSE
84
84
  - README.md
85
85
  - Rakefile
86
- - fluent-plugin-archagent-0.1.0.gem
87
86
  - fluent-plugin-archagent.gemspec
88
87
  - lib/fluent/plugin/out_archagent.rb
89
88
  - test/helper.rb