adp-fluent-plugin-graphite 0.0.19 → 0.1.0

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: 4ec7994190ada35fdac587e172689dbf5dbac317a81908e9c887ef5b9bcff086
4
- data.tar.gz: a7d66b34f986653f8746d27bb6f5831f53ff9c3e4c486a4d55af041421b14b7b
3
+ metadata.gz: dcb0b99995de71b515fd3b5934589d95af6cfdbdbca9ccac9ac6ac349720d02c
4
+ data.tar.gz: 384393b27c068712191daeb631a16fb5c7f9ef641bad7f8e396ce7733283569f
5
5
  SHA512:
6
- metadata.gz: 510c48db7df2865b141198ad3f0eb0f14a4a9994e197673b55659558a1b10442cc1d70e159d8a2a49b3ae878c2d6081f99f82182ebca51cea0418bb2c6b988fc
7
- data.tar.gz: 0b6b35d3afba2374aa90e204c88cbb2ec850ad3d90169030d48464e7a19f9eece20a678df9ad1a9c1de4107aeba81f0bd1869228a56d840752c1ef4960b9e000
6
+ metadata.gz: ad9e87463588d24c7fcad9b90d54993aecf05269284c3e3b740f66d038e96c9e28468de7ee58cdc0d73455fd7762203eaa1e416f2e60416e1ecd1ee9b542b559
7
+ data.tar.gz: 4a58e1b33b50e3c38de527a6a97c7e5a649b5a77955a9c4783054db6f1aaa10c26703428078f9acf5082546a980ed156ca702bfcfff3bcd9b7fc6ef58c6cc9d7
@@ -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.19'
6
+ gem.version = '0.1.0'
7
7
  gem.authors = ['Aleksander Dudek']
8
8
  gem.email = 'adudek4@gmail.com'
9
9
  gem.homepage = ''
@@ -0,0 +1,28 @@
1
+ require 'fluent/plugin/output'
2
+
3
+ module Fluent::Plugin
4
+ class GraphiteFilter < Fluent::Plugin::Filter
5
+ Fluent::Plugin.register_filter('graphite', self)
6
+ config_param :host, :string
7
+ config_param :port, :integer, default: 2003
8
+ config_param :prefix, :string, default: 'adp-fluentd-agent'
9
+ config_param :monitoring_key, :string
10
+ config_param :max_retries, :integer, default: 3
11
+ config_param :log_level, :string, default: 'info'
12
+
13
+ def start
14
+ super
15
+ ::Graphite.init_client(@log_level, @host, @port)
16
+ end
17
+
18
+ def configure(conf)
19
+ super
20
+ end
21
+
22
+ def filter(tag, time, record)
23
+ metrics = ::Graphite.format_metrics(tag, record)
24
+ ::Graphite.post(metrics, time)
25
+ record
26
+ end
27
+ end
28
+ 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,8 +1,10 @@
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
@@ -11,15 +13,9 @@ module Fluent::Plugin
11
13
  config_param :max_retries, :integer, default: 3
12
14
  config_param :log_level, :string, default: 'info'
13
15
 
14
- def initialize
15
- super
16
- require 'graphite-api'
17
- log.info("Initialize graphite plugin")
18
- end
19
-
20
16
  def start
21
17
  super
22
- connect_client!
18
+ ::Graphite.init_client(@log_level, @host, @port)
23
19
  end
24
20
 
25
21
  def configure(conf)
@@ -29,74 +25,13 @@ module Fluent::Plugin
29
25
  def process(tag, es)
30
26
  es.each do |time, record|
31
27
  emit_tag = tag.dup
32
- metrics = format_metrics(emit_tag, record)
28
+ metrics = ::Graphite.format_metrics(emit_tag, record)
33
29
 
34
30
  # implemented to immediate call post method in this loop, because graphite-api.gem has the buffers.
35
- post(metrics, time)
36
- end
37
-
38
- end
39
-
40
- def format_metrics(tag, record)
41
- metrics = {}
42
- key = @monitoring_key + "." + @prefix + "." + tag
43
- metrics[key] = 1
44
- metrics
45
- end
46
-
47
- def post(metric, time)
48
- trial ||= 1
49
- @client.metrics(metric, time)
50
- rescue Errno::ETIMEDOUT
51
- # after long periods with nothing emitted, the connection will be closed and result in timeout
52
- if trial <= @max_retries
53
- log.warn "out_graphite: connection timeout to #{@host}:#{@port}. Reconnecting... "
54
- trial += 1
55
- connect_client!
56
- retry
57
- else
58
- log.error "out_graphite: ERROR: connection timeout to #{@host}:#{@port}. Exceeded max_retries #{@max_retries}"
31
+ ::Graphite.post(metrics, time)
59
32
  end
60
- rescue Errno::ECONNREFUSED
61
- log.warn "out_graphite: connection refused by #{@host}:#{@port}"
62
- rescue SocketError => se
63
- log.warn "out_graphite: socket error by #{@host}:#{@port} :#{se}"
64
- rescue StandardError => e
65
- log.error "out_graphite: ERROR: #{e}"
66
- end
67
33
 
68
- def init_logger
69
- if @log_level == 'debug'
70
- GraphiteAPI::Logger.init level: :debug
71
- end
72
- if @log_level == 'warn'
73
- GraphiteAPI::Logger.init level: :warn
74
- end
75
- if @log_level == 'info'
76
- GraphiteAPI::Logger.init level: :info
77
- end
78
- if @log_level == 'error'
79
- GraphiteAPI::Logger.init level: :error
80
- end
81
34
  end
82
35
 
83
- def connect_client!
84
- options = {
85
- # Required: valid URI {udp,tcp}://host:port/?timeout=seconds
86
- graphite: "tcp://#{@host}:#{@port}",
87
-
88
- # Optional: results are aggregated in 60 seconds slices ( default is 60 )
89
- slice: 30,
90
-
91
- # Optional: send to graphite every 60 seconds ( default is 0 - direct send )
92
- interval: 30,
93
-
94
- # Optional: set the max age in seconds for records reanimation ( default is 12 hours )
95
- cache: 4 * 60 * 60,
96
- }
97
- @client = GraphiteAPI.new options
98
- init_logger
99
- log.info("Starting graphite client")
100
- end
101
36
  end
102
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.0.19
4
+ version: 0.1.0
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