adp-fluent-plugin-graphite 0.0.1 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/adp-fluent-plugin-graphite.gemspec +1 -1
- data/lib/fluent/plugin/out_graphite.rb +83 -100
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e3a6f748d7f9d2f5fd0d477ae4530ebd3066b2f6028bdd5fd9b97fab31d8017
|
4
|
+
data.tar.gz: 3b7d612e03aff2734fcbffb67399082eb57e015916c7e53ba07b657b88db3b3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9defa26210f58460b0d142031dcc7bb3207734231dfd4e3b1b89305b875de651a51b6cc11a472cc61549c011fa7a872644b7364ea48c12a44b12b1ca9937dd8a
|
7
|
+
data.tar.gz: a4b6bbdff883ee47d1692c458252102b9d8e6aa5b6002d8abf8e1c6754ea69cf34050faaa99cd833d2539b0810d1c0d378be1a8a2092766387e83d5858f69931
|
@@ -3,7 +3,7 @@ $:.push File.expand_path('../lib', __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.name = 'adp-fluent-plugin-graphite'
|
6
|
-
gem.version = '0.0.
|
6
|
+
gem.version = '0.0.5'
|
7
7
|
gem.authors = ['Satoshi SUZUKI']
|
8
8
|
gem.email = 'studio3104.com@gmail.com'
|
9
9
|
gem.homepage = 'https://github.com/studio3104/fluent-plugin-graphite'
|
@@ -1,116 +1,99 @@
|
|
1
|
-
require 'fluent/
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
def initialize
|
21
|
-
super
|
22
|
-
require 'graphite-api'
|
23
|
-
end
|
24
|
-
|
25
|
-
def start
|
26
|
-
super
|
27
|
-
connect_client!
|
28
|
-
end
|
29
|
-
|
30
|
-
def configure(conf)
|
31
|
-
super
|
32
|
-
|
33
|
-
if !['prefix', 'suffix', 'ignore'].include?(@tag_for)
|
34
|
-
raise Fluent::ConfigError, 'out_graphite: can specify to tag_for only prefix, suffix or ignore'
|
35
|
-
end
|
36
|
-
|
37
|
-
if !@name_keys && !@name_key_pattern
|
38
|
-
raise Fluent::ConfigError, 'out_graphite: missing both of name_keys and name_key_pattern'
|
39
|
-
end
|
40
|
-
if @name_keys && @name_key_pattern
|
41
|
-
raise Fluent::ConfigError, 'out_graphite: cannot specify both of name_keys and name_key_pattern'
|
1
|
+
require 'fluent/plugin/output'
|
2
|
+
|
3
|
+
module Fluent::Plugin
|
4
|
+
class GraphiteOutput < Output
|
5
|
+
Fluent::Plugin.register_output('graphite', self)
|
6
|
+
|
7
|
+
config_param :host, :string
|
8
|
+
config_param :port, :integer, default: 2003
|
9
|
+
config_param :tag_for, :string, default: 'prefix'
|
10
|
+
config_param :name_keys, :string, default: nil
|
11
|
+
config_param :name_key_pattern, :string, default: nil
|
12
|
+
config_param :max_retries, :integer, default: 3
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
super
|
16
|
+
require 'graphite-api'
|
17
|
+
log.info("Initialize graphite plugin")
|
42
18
|
end
|
43
19
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
if @name_key_pattern
|
48
|
-
@name_key_pattern = Regexp.new(@name_key_pattern)
|
20
|
+
def start
|
21
|
+
super
|
22
|
+
connect_client!
|
49
23
|
end
|
50
|
-
# How many times to retry the call if timeout raised
|
51
|
-
@max_retries ||= 3
|
52
|
-
end
|
53
24
|
|
54
|
-
|
55
|
-
|
56
|
-
emit_tag = tag.dup
|
57
|
-
filter_record(emit_tag, time, record)
|
58
|
-
next unless metrics = format_metrics(emit_tag, record)
|
25
|
+
def configure(conf)
|
26
|
+
super
|
59
27
|
|
60
|
-
|
61
|
-
|
28
|
+
if @name_keys
|
29
|
+
@name_keys = @name_keys.split(',')
|
30
|
+
end
|
62
31
|
end
|
63
32
|
|
64
|
-
chain
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
else # defined @name_key_pattern
|
71
|
-
record.select { |k,v| @name_key_pattern.match(k.to_s) }
|
72
|
-
end
|
33
|
+
def emit(tag, es, chain)
|
34
|
+
es.each do |time, record|
|
35
|
+
emit_tag = tag.dup
|
36
|
+
filter_record(emit_tag, time, record)
|
37
|
+
log.info("Emit graphite plugin: #{record}")
|
38
|
+
next unless metrics = format_metrics(emit_tag, record)
|
73
39
|
|
74
|
-
|
40
|
+
# implemented to immediate call post method in this loop, because graphite-api.gem has the buffers.
|
41
|
+
post(metrics, time)
|
42
|
+
end
|
75
43
|
|
76
|
-
|
77
|
-
|
78
|
-
filtered_record.each do |k, v|
|
79
|
-
key = case @tag_for
|
80
|
-
when 'ignore' then k.to_s
|
81
|
-
when 'prefix' then "#{tag}.#{k}"
|
82
|
-
when 'suffix' then "#{k}.#{tag}"
|
83
|
-
end
|
44
|
+
chain.next
|
45
|
+
end
|
84
46
|
|
85
|
-
|
86
|
-
|
47
|
+
def format_metrics(tag, record)
|
48
|
+
filtered_record = if @name_keys
|
49
|
+
record.select { |k, v| @name_keys.include?(k.to_s) }
|
50
|
+
else
|
51
|
+
# defined @name_key_pattern
|
52
|
+
record.select { |k, v| @name_key_pattern.match(k.to_s) }
|
53
|
+
end
|
54
|
+
|
55
|
+
return nil if filtered_record.empty?
|
56
|
+
|
57
|
+
metrics = {}
|
58
|
+
tag = tag.sub(/\.$/, '') # may include a dot at the end of the emit_tag fluent-mixin-rewrite-tag-name returns. remove it.
|
59
|
+
filtered_record.each do |k, v|
|
60
|
+
key = case @tag_for
|
61
|
+
when 'ignore' then k.to_s
|
62
|
+
when 'prefix' then "#{tag}.#{k}"
|
63
|
+
when 'suffix' then "#{k}.#{tag}"
|
64
|
+
end
|
65
|
+
|
66
|
+
key = key.gsub(/(\s|\/)+/, '_') # cope with in the case of containing symbols or spaces in the key of the record like in_dstat.
|
67
|
+
metrics[key] = v.to_f
|
68
|
+
end
|
69
|
+
metrics
|
87
70
|
end
|
88
|
-
metrics
|
89
|
-
end
|
90
71
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
72
|
+
def post(metrics, time)
|
73
|
+
trial ||= 1
|
74
|
+
@client.metrics(metrics, time)
|
75
|
+
log.warn("Sending metrics: #{metrics}")
|
76
|
+
rescue Errno::ETIMEDOUT
|
77
|
+
# after long periods with nothing emitted, the connection will be closed and result in timeout
|
78
|
+
if trial <= @max_retries
|
79
|
+
log.warn "out_graphite: connection timeout to #{@host}:#{@port}. Reconnecting... "
|
80
|
+
trial += 1
|
81
|
+
connect_client!
|
82
|
+
retry
|
83
|
+
else
|
84
|
+
log.error "out_graphite: ERROR: connection timeout to #{@host}:#{@port}. Exceeded max_retries #{@max_retries}"
|
85
|
+
end
|
86
|
+
rescue Errno::ECONNREFUSED
|
87
|
+
log.warn "out_graphite: connection refused by #{@host}:#{@port}"
|
88
|
+
rescue SocketError => se
|
89
|
+
log.warn "out_graphite: socket error by #{@host}:#{@port} :#{se}"
|
90
|
+
rescue StandardError => e
|
91
|
+
log.error "out_graphite: ERROR: #{e}"
|
104
92
|
end
|
105
|
-
rescue Errno::ECONNREFUSED
|
106
|
-
log.warn "out_graphite: connection refused by #{@host}:#{@port}"
|
107
|
-
rescue SocketError => se
|
108
|
-
log.warn "out_graphite: socket error by #{@host}:#{@port} :#{se}"
|
109
|
-
rescue StandardError => e
|
110
|
-
log.error "out_graphite: ERROR: #{e}"
|
111
|
-
end
|
112
93
|
|
113
|
-
|
114
|
-
|
94
|
+
def connect_client!
|
95
|
+
@client = GraphiteAPI.new(graphite: "#{@host}:#{@port}")
|
96
|
+
log.info("starting client")
|
97
|
+
end
|
115
98
|
end
|
116
99
|
end
|