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 +4 -4
- data/fluent-plugin-archagent.gemspec +1 -1
- data/lib/fluent/plugin/out_archagent.rb +65 -67
- metadata +2 -3
- data/fluent-plugin-archagent-0.1.0.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efe242f9fe55889fff7c4a4619eddab44fd67c68
|
4
|
+
data.tar.gz: 54eceb112086c82ee1e2573fc8b6671a5a27f998
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0757c57125978ac63c69b2aedbbdb9c8d086adb92a5e24d5251895797c5e74997c5fcdbf3bfae90fdb0e11df9adfb4459ed6bf5c1d63c2d56fa92505abb9a38
|
7
|
+
data.tar.gz: f0d14d6fe705683579f025d12787635d7758aed6279e13f322e050c86ea957f42e46057d422636fa8180ba31c8bec9380f59a1ee5e2c440eaca5460e600deb84
|
@@ -1,93 +1,91 @@
|
|
1
1
|
module Fluent::Plugin
|
2
|
-
|
3
|
-
|
2
|
+
class ArchagentOutput < Fluent::BufferedOutput
|
3
|
+
Fluent::Plugin.register_output("archagent", self)
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
def initialize
|
6
|
+
super
|
7
|
+
require 'net/http'
|
8
|
+
require 'uri'
|
9
|
+
end
|
10
10
|
|
11
|
-
|
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
|
-
|
13
|
+
config_param :port, :string, default: '8118'
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
def configure(conf)
|
16
|
+
super
|
17
17
|
|
18
|
-
|
19
|
-
|
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
|
-
|
22
|
-
|
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
|
-
|
25
|
-
|
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
|
-
|
31
|
-
|
32
|
-
rescue URI::InvalidURIError
|
33
|
-
raise Fluent::ConfigError, 'port invalid'
|
35
|
+
def start
|
36
|
+
super
|
34
37
|
end
|
35
38
|
|
36
|
-
|
37
|
-
|
38
|
-
@http.open_timeout = @http_open_timeout
|
39
|
-
end
|
39
|
+
def shutdown
|
40
|
+
super
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
end
|
42
|
+
disconnect
|
43
|
+
end
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|
-
|
78
|
+
protected
|
81
79
|
|
82
|
-
|
83
|
-
|
80
|
+
def create_request(data)
|
81
|
+
request = Net::HTTP::Post.new(@uri.request_uri)
|
84
82
|
|
85
|
-
|
86
|
-
|
83
|
+
# Headers
|
84
|
+
request['Content-Type'] = 'application/json'
|
87
85
|
|
88
|
-
|
89
|
-
|
90
|
-
|
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.
|
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-
|
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
|
Binary file
|