adp-fluent-plugin-graphite 0.0.2 → 0.0.3

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