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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 66ea8fa9a5c94707aeb094d4615bc5868d30b3a84a2a1df2918fe7f38b7d687e
4
- data.tar.gz: 7c11a161f98d059a57834ecd300d611b1381417278062b46eb90f39a35a1c246
3
+ metadata.gz: 5e3a6f748d7f9d2f5fd0d477ae4530ebd3066b2f6028bdd5fd9b97fab31d8017
4
+ data.tar.gz: 3b7d612e03aff2734fcbffb67399082eb57e015916c7e53ba07b657b88db3b3c
5
5
  SHA512:
6
- metadata.gz: 9edc6e64ad578294e63eb4d32a2e2a2ff428346acb9cc8dfb64bf2c365093a50bca13019dc5f01ffa1b1b01f552c61b9d383453d70e9b3300abac7b9ed218e37
7
- data.tar.gz: 6614451a63fd144a78c1794a0ca5a2a51ad68b5c206e0f7ac9d492725be89aa5af4405f4009edabfd531b65e1ab53885f2f964cf8eaf19503b57ab012e683090
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.1'
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/mixin/rewrite_tag_name'
2
-
3
- class Fluent::GraphiteOutput < Fluent::Output
4
- Fluent::Plugin.register_output('graphite', self)
5
-
6
- include Fluent::HandleTagNameMixin
7
- include Fluent::Mixin::RewriteTagName
8
-
9
- config_param :host, :string
10
- config_param :port, :integer, default: 2003
11
- config_param :tag_for, :string, default: 'prefix'
12
- config_param :name_keys, :string, default: nil
13
- config_param :name_key_pattern, :string, default: nil
14
-
15
- # Define `log` method for v0.10.42 or earlier
16
- unless method_defined?(:log)
17
- define_method(:log) { $log }
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
- if @name_keys
45
- @name_keys = @name_keys.split(',')
46
- end
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
- def emit(tag, es, chain)
55
- es.each do |time, record|
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
- # implemented to immediate call post method in this loop, because graphite-api.gem has the buffers.
61
- post(metrics, time)
28
+ if @name_keys
29
+ @name_keys = @name_keys.split(',')
30
+ end
62
31
  end
63
32
 
64
- chain.next
65
- end
66
-
67
- def format_metrics(tag, record)
68
- filtered_record = if @name_keys
69
- record.select { |k,v| @name_keys.include?(k.to_s) }
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
- return nil if filtered_record.empty?
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
- metrics = {}
77
- tag = tag.sub(/\.$/, '') # may include a dot at the end of the emit_tag fluent-mixin-rewrite-tag-name returns. remove it.
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
- key = key.gsub(/(\s|\/)+/, '_') # cope with in the case of containing symbols or spaces in the key of the record like in_dstat.
86
- metrics[key] = v.to_f
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
- def post(metrics, time)
92
- trial ||= 1
93
- @client.metrics(metrics, time)
94
- log.debug "Sending metrics: #{metrics}"
95
- rescue Errno::ETIMEDOUT
96
- # after long periods with nothing emitted, the connection will be closed and result in timeout
97
- if trial <= @max_retries
98
- log.warn "out_graphite: connection timeout to #{@host}:#{@port}. Reconnecting... "
99
- trial += 1
100
- connect_client!
101
- retry
102
- else
103
- log.error "out_graphite: ERROR: connection timeout to #{@host}:#{@port}. Exceeded max_retries #{@max_retries}"
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
- def connect_client!
114
- @client = GraphiteAPI.new(graphite: "#{@host}:#{@port}")
94
+ def connect_client!
95
+ @client = GraphiteAPI.new(graphite: "#{@host}:#{@port}")
96
+ log.info("starting client")
97
+ end
115
98
  end
116
99
  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.0.1
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Satoshi SUZUKI