adp-fluent-plugin-graphite 0.0.2 → 0.0.6

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: 052c0e2d0e66ba05cb94a995f040c436ada3cad27d1386850d2aca4659152189
4
+ data.tar.gz: d6333c8cbead5da773384aa63149518d1b9fb8dfbac2dbcec35b1127b1688171
5
5
  SHA512:
6
- metadata.gz: 6a15fc0687a594a272553b7e785690832822738aaab8672fe82c05577bbeed428587773101e7ef179bf0e4924a03ca8c9a0803ccc94ad149bb5dc10838f2c2b0
7
- data.tar.gz: 827807f99db84afdd190c5d7a6640a4b7b5337224b92e50944eb86497eb2aab6240ac949ea338c848e86887e2c15590f7b89bc6e207aec03e341cdfe6f84a994
6
+ metadata.gz: fd9dd5a45669dec38a3d7498070bd7ac2ad56b8a7c9d150668956270bcb8d4c3a0934f26681929277189afdcdded2c8a8583ac3046b5289c781e2ee567c2d54e
7
+ data.tar.gz: df3548004608c62f59da0cc3cea317ec3115c685dd7cb419b2182d16337d8cca4ce57209d25fcc0f3bd509c303d294db1be4f3437ac70217ea9dff2dcfb2d044
@@ -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.6'
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,98 @@
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
+ log.info("Emit graphite plugin: #{record}")
37
+ next unless metrics = format_metrics(emit_tag, record)
73
38
 
74
- return nil if filtered_record.empty?
39
+ # implemented to immediate call post method in this loop, because graphite-api.gem has the buffers.
40
+ post(metrics, time)
41
+ end
75
42
 
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
43
+ chain.next
44
+ end
84
45
 
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
46
+ def format_metrics(tag, record)
47
+ filtered_record = if @name_keys
48
+ record.select { |k, v| @name_keys.include?(k.to_s) }
49
+ else
50
+ # defined @name_key_pattern
51
+ record.select { |k, v| @name_key_pattern.match(k.to_s) }
52
+ end
53
+
54
+ return nil if filtered_record.empty?
55
+
56
+ metrics = {}
57
+ tag = tag.sub(/\.$/, '') # may include a dot at the end of the emit_tag fluent-mixin-rewrite-tag-name returns. remove it.
58
+ filtered_record.each do |k, v|
59
+ key = case @tag_for
60
+ when 'ignore' then k.to_s
61
+ when 'prefix' then "#{tag}.#{k}"
62
+ when 'suffix' then "#{k}.#{tag}"
63
+ end
64
+
65
+ key = key.gsub(/(\s|\/)+/, '_') # cope with in the case of containing symbols or spaces in the key of the record like in_dstat.
66
+ metrics[key] = v.to_f
67
+ end
68
+ metrics
87
69
  end
88
- metrics
89
- end
90
70
 
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}"
71
+ def post(metrics, time)
72
+ trial ||= 1
73
+ @client.metrics(metrics, time)
74
+ log.warn("Sending metrics: #{metrics}")
75
+ rescue Errno::ETIMEDOUT
76
+ # after long periods with nothing emitted, the connection will be closed and result in timeout
77
+ if trial <= @max_retries
78
+ log.warn "out_graphite: connection timeout to #{@host}:#{@port}. Reconnecting... "
79
+ trial += 1
80
+ connect_client!
81
+ retry
82
+ else
83
+ log.error "out_graphite: ERROR: connection timeout to #{@host}:#{@port}. Exceeded max_retries #{@max_retries}"
84
+ end
85
+ rescue Errno::ECONNREFUSED
86
+ log.warn "out_graphite: connection refused by #{@host}:#{@port}"
87
+ rescue SocketError => se
88
+ log.warn "out_graphite: socket error by #{@host}:#{@port} :#{se}"
89
+ rescue StandardError => e
90
+ log.error "out_graphite: ERROR: #{e}"
104
91
  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
92
 
113
- def connect_client!
114
- @client = GraphiteAPI.new(graphite: "#{@host}:#{@port}")
93
+ def connect_client!
94
+ @client = GraphiteAPI.new(graphite: "#{@host}:#{@port}")
95
+ log.info("starting client")
96
+ end
115
97
  end
116
98
  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.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Satoshi SUZUKI