adp-fluent-plugin-graphite 0.0.18 → 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/adp-fluent-plugin-graphite.gemspec +1 -1
- data/lib/fluent/plugin/filter_graphite.rb +30 -0
- data/lib/fluent/plugin/graphite.rb +75 -0
- data/lib/fluent/plugin/out_graphite.rb +4 -59
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91a11f6d33ffb459b113d744d38951631f6f8a43203799e23163da7350e2c93d
|
4
|
+
data.tar.gz: cb51400a9d54217313775338329e73407e40868a0152e0f7452a22d7aa2c0334
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2286a09376b57fe11e4f09e44d190f81213a3ed99f54b66c6756e70ebaf570424b1809020ccbf028240a770c5b16b3cc3a1c1287b7d14cf28907fea6b02085d
|
7
|
+
data.tar.gz: 71af86c21bf2ce619c21e70d64b599869de200a5164cced81db56d62e9898b8d0e5ace5ce9d44986f4bcbc48894f4e6e591e323369945d635269c777eb3ce4b8
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'fluent/plugin/output'
|
2
|
+
|
3
|
+
module Fluent::Plugin
|
4
|
+
class GraphiteFilter < Fluent::Plugin::Filter
|
5
|
+
Fluent::Plugin.register_filter('graphite', self)
|
6
|
+
include Fluent::Plugin::Graphite
|
7
|
+
|
8
|
+
config_param :host, :string
|
9
|
+
config_param :port, :integer, default: 2003
|
10
|
+
config_param :prefix, :string, default: 'adp-fluentd-agent'
|
11
|
+
config_param :monitoring_key, :string
|
12
|
+
config_param :max_retries, :integer, default: 3
|
13
|
+
config_param :log_level, :string, default: 'info'
|
14
|
+
|
15
|
+
def start
|
16
|
+
super
|
17
|
+
init_client(@log_level, @host, @port)
|
18
|
+
end
|
19
|
+
|
20
|
+
def configure(conf)
|
21
|
+
super
|
22
|
+
end
|
23
|
+
|
24
|
+
def filter(tag, time, record)
|
25
|
+
metrics = format_metrics(tag, record)
|
26
|
+
post(metrics, time)
|
27
|
+
record
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Fluent
|
2
|
+
module Plugin
|
3
|
+
module Graphite
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
super
|
7
|
+
require 'graphite-api'
|
8
|
+
log.info("Initialize graphite plugin")
|
9
|
+
end
|
10
|
+
|
11
|
+
def init_logger(log_level)
|
12
|
+
if log_level == 'debug'
|
13
|
+
GraphiteAPI::Logger.init level: :debug
|
14
|
+
end
|
15
|
+
if log_level == 'warn'
|
16
|
+
GraphiteAPI::Logger.init level: :warn
|
17
|
+
end
|
18
|
+
if log_level == 'info'
|
19
|
+
GraphiteAPI::Logger.init level: :info
|
20
|
+
end
|
21
|
+
if log_level == 'error'
|
22
|
+
GraphiteAPI::Logger.init level: :error
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def init_client(log_level, host, port)
|
27
|
+
options = {
|
28
|
+
# Required: valid URI {udp,tcp}://host:port/?timeout=seconds
|
29
|
+
graphite: "tcp://#{host}:#{port}",
|
30
|
+
|
31
|
+
# Optional: results are aggregated in 60 seconds slices ( default is 60 )
|
32
|
+
slice: 30,
|
33
|
+
|
34
|
+
# Optional: send to graphite every 60 seconds ( default is 0 - direct send )
|
35
|
+
interval: 30,
|
36
|
+
|
37
|
+
# Optional: set the max age in seconds for records reanimation ( default is 12 hours )
|
38
|
+
cache: 4 * 60 * 60,
|
39
|
+
}
|
40
|
+
@client = GraphiteAPI.new options
|
41
|
+
init_logger(log_level)
|
42
|
+
log.info("Starting graphite client")
|
43
|
+
end
|
44
|
+
|
45
|
+
def format_metrics(tag, record)
|
46
|
+
metrics = {}
|
47
|
+
key = @monitoring_key + "." + @prefix + "." + tag
|
48
|
+
metrics[key] = 1
|
49
|
+
metrics
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
def post(metric, time)
|
54
|
+
trial ||= 1
|
55
|
+
@client.metrics(metric, time)
|
56
|
+
rescue Errno::ETIMEDOUT
|
57
|
+
# after long periods with nothing emitted, the connection will be closed and result in timeout
|
58
|
+
if trial <= @max_retries
|
59
|
+
log.warn "out_graphite: connection timeout to #{@host}:#{@port}. Reconnecting... "
|
60
|
+
trial += 1
|
61
|
+
::Graphite.init_client(@log_level, @host, @port)
|
62
|
+
retry
|
63
|
+
else
|
64
|
+
log.error "out_graphite: ERROR: connection timeout to #{@host}:#{@port}. Exceeded max_retries #{@max_retries}"
|
65
|
+
end
|
66
|
+
rescue Errno::ECONNREFUSED
|
67
|
+
log.warn "out_graphite: connection refused by #{@host}:#{@port}"
|
68
|
+
rescue SocketError => se
|
69
|
+
log.warn "out_graphite: socket error by #{@host}:#{@port} :#{se}"
|
70
|
+
rescue StandardError => e
|
71
|
+
log.error "out_graphite: ERROR: #{e}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -1,38 +1,30 @@
|
|
1
|
+
require 'fluent/plugin/graphite'
|
1
2
|
require 'fluent/plugin/output'
|
2
3
|
|
3
4
|
module Fluent::Plugin
|
4
5
|
class GraphiteOutput < Fluent::Plugin::Output
|
5
6
|
Fluent::Plugin.register_output('graphite', self)
|
7
|
+
include Fluent::Plugin::Graphite
|
6
8
|
|
7
9
|
config_param :host, :string
|
8
10
|
config_param :port, :integer, default: 2003
|
9
11
|
config_param :prefix, :string, default: 'adp-fluentd-agent'
|
10
12
|
config_param :monitoring_key, :string
|
11
|
-
config_param :name_key_pattern, :string, default: nil
|
12
13
|
config_param :max_retries, :integer, default: 3
|
13
|
-
|
14
|
-
def initialize
|
15
|
-
super
|
16
|
-
require 'graphite-api'
|
17
|
-
log.info("Initialize graphite plugin")
|
18
|
-
end
|
14
|
+
config_param :log_level, :string, default: 'info'
|
19
15
|
|
20
16
|
def start
|
21
17
|
super
|
22
|
-
|
18
|
+
init_client(@log_level, @host, @port)
|
23
19
|
end
|
24
20
|
|
25
21
|
def configure(conf)
|
26
22
|
super
|
27
|
-
if @name_keys
|
28
|
-
@name_keys = @name_keys.split(',')
|
29
|
-
end
|
30
23
|
end
|
31
24
|
|
32
25
|
def process(tag, es)
|
33
26
|
es.each do |time, record|
|
34
27
|
emit_tag = tag.dup
|
35
|
-
log.info("Emit graphite plugin: #{record}")
|
36
28
|
metrics = format_metrics(emit_tag, record)
|
37
29
|
|
38
30
|
# implemented to immediate call post method in this loop, because graphite-api.gem has the buffers.
|
@@ -41,52 +33,5 @@ module Fluent::Plugin
|
|
41
33
|
|
42
34
|
end
|
43
35
|
|
44
|
-
def format_metrics(tag, record)
|
45
|
-
metrics = {}
|
46
|
-
key = @monitoring_key + "." + @prefix + "." + tag
|
47
|
-
metrics[key] = 1
|
48
|
-
metrics
|
49
|
-
end
|
50
|
-
|
51
|
-
def post(metric, time)
|
52
|
-
trial ||= 1
|
53
|
-
@client.metrics(metric, time)
|
54
|
-
log.warn("Sending metrics: #{metric}")
|
55
|
-
rescue Errno::ETIMEDOUT
|
56
|
-
# after long periods with nothing emitted, the connection will be closed and result in timeout
|
57
|
-
if trial <= @max_retries
|
58
|
-
log.warn "out_graphite: connection timeout to #{@host}:#{@port}. Reconnecting... "
|
59
|
-
trial += 1
|
60
|
-
connect_client!
|
61
|
-
retry
|
62
|
-
else
|
63
|
-
log.error "out_graphite: ERROR: connection timeout to #{@host}:#{@port}. Exceeded max_retries #{@max_retries}"
|
64
|
-
end
|
65
|
-
rescue Errno::ECONNREFUSED
|
66
|
-
log.warn "out_graphite: connection refused by #{@host}:#{@port}"
|
67
|
-
rescue SocketError => se
|
68
|
-
log.warn "out_graphite: socket error by #{@host}:#{@port} :#{se}"
|
69
|
-
rescue StandardError => e
|
70
|
-
log.error "out_graphite: ERROR: #{e}"
|
71
|
-
end
|
72
|
-
|
73
|
-
def connect_client!
|
74
|
-
options = {
|
75
|
-
# Required: valid URI {udp,tcp}://host:port/?timeout=seconds
|
76
|
-
graphite: "tcp://#{@host}:#{@port}",
|
77
|
-
|
78
|
-
# Optional: results are aggregated in 60 seconds slices ( default is 60 )
|
79
|
-
slice: 30,
|
80
|
-
|
81
|
-
# Optional: send to graphite every 60 seconds ( default is 0 - direct send )
|
82
|
-
interval: 30,
|
83
|
-
|
84
|
-
# Optional: set the max age in seconds for records reanimation ( default is 12 hours )
|
85
|
-
cache: 4 * 60 * 60,
|
86
|
-
}
|
87
|
-
@client = GraphiteAPI.new options
|
88
|
-
GraphiteAPI::Logger.init level: :debug
|
89
|
-
log.info("starting client")
|
90
|
-
end
|
91
36
|
end
|
92
37
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adp-fluent-plugin-graphite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aleksander Dudek
|
@@ -79,6 +79,8 @@ files:
|
|
79
79
|
- README.md
|
80
80
|
- Rakefile
|
81
81
|
- adp-fluent-plugin-graphite.gemspec
|
82
|
+
- lib/fluent/plugin/filter_graphite.rb
|
83
|
+
- lib/fluent/plugin/graphite.rb
|
82
84
|
- lib/fluent/plugin/out_graphite.rb
|
83
85
|
- test/helper.rb
|
84
86
|
- test/plugin/test_out_graphite.rb
|