adp-fluent-plugin-graphite 0.0.17 → 0.1.1
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 +4 -4
- data/lib/fluent/plugin/filter_graphite.rb +30 -0
- data/lib/fluent/plugin/graphite.rb +75 -0
- data/lib/fluent/plugin/out_graphite.rb +7 -61
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 972305dfab080939201cd709b16d6530d49fbfeb80cd0bad2d4f182a6f7304a4
|
4
|
+
data.tar.gz: 765fdaa78c9d148294e5741bee401d5498ac9eac0a390b309bb07b87c1c303e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a89798fa104f36eb429c4ad40456e0360c55c0f935a68c5aee69321bd4cbeb2dc1e8972da628e8cb33166f9d425accf7cdd9fd6375c34259cb789320d2e157b
|
7
|
+
data.tar.gz: 5086fa5cfbfec7d4b7d3003009a773068167fe1710241dd0c629ed97c50f049979b9b366f2dba0991f74e9e10f5fb0473189b20ed1c646124a9a65c258aeeeb0
|
@@ -3,10 +3,10 @@ $:.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.
|
7
|
-
gem.authors = ['
|
8
|
-
gem.email = '
|
9
|
-
gem.homepage = '
|
6
|
+
gem.version = '0.1.1'
|
7
|
+
gem.authors = ['Aleksander Dudek']
|
8
|
+
gem.email = 'adudek4@gmail.com'
|
9
|
+
gem.homepage = ''
|
10
10
|
gem.description = 'fluentd output plugin to send metrics to graphite'
|
11
11
|
gem.summary = gem.description
|
12
12
|
gem.licenses = ['MIT']
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'fluent/plugin/output'
|
2
|
+
|
3
|
+
module Fluent::Plugin
|
4
|
+
class GraphiteFilter < Fluent::Plugin::Filter
|
5
|
+
Fluent::Plugin.register_filter('graphite', self)
|
6
|
+
include Fluent::Plugin::Graphite
|
7
|
+
|
8
|
+
config_param :host, :string
|
9
|
+
config_param :port, :integer, default: 2003
|
10
|
+
config_param :prefix, :string, default: 'adp-fluentd-agent'
|
11
|
+
config_param :monitoring_key, :string
|
12
|
+
config_param :max_retries, :integer, default: 3
|
13
|
+
config_param :log_level, :string, default: 'info'
|
14
|
+
|
15
|
+
def start
|
16
|
+
super
|
17
|
+
Graphite.init_client(@log_level, @host, @port)
|
18
|
+
end
|
19
|
+
|
20
|
+
def configure(conf)
|
21
|
+
super
|
22
|
+
end
|
23
|
+
|
24
|
+
def filter(tag, time, record)
|
25
|
+
metrics = Graphite.format_metrics(tag, record)
|
26
|
+
Graphite.post(metrics, time)
|
27
|
+
record
|
28
|
+
end
|
29
|
+
end
|
30
|
+
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,91 +1,37 @@
|
|
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
|
9
|
-
config_param :
|
11
|
+
config_param :prefix, :string, default: 'adp-fluentd-agent'
|
10
12
|
config_param :monitoring_key, :string
|
11
|
-
config_param :name_key_pattern, :string, default: nil
|
12
13
|
config_param :max_retries, :integer, default: 3
|
13
|
-
|
14
|
-
def initialize
|
15
|
-
super
|
16
|
-
require 'graphite-api'
|
17
|
-
log.info("Initialize graphite plugin")
|
18
|
-
end
|
14
|
+
config_param :log_level, :string, default: 'info'
|
19
15
|
|
20
16
|
def start
|
21
17
|
super
|
22
|
-
|
18
|
+
Graphite.init_client(@log_level, @host, @port)
|
23
19
|
end
|
24
20
|
|
25
21
|
def configure(conf)
|
26
22
|
super
|
27
|
-
if @name_keys
|
28
|
-
@name_keys = @name_keys.split(',')
|
29
|
-
end
|
30
23
|
end
|
31
24
|
|
32
25
|
def process(tag, es)
|
33
26
|
es.each do |time, record|
|
34
27
|
emit_tag = tag.dup
|
35
|
-
|
36
|
-
metrics = format_metrics(emit_tag, record)
|
28
|
+
metrics = Graphite.format_metrics(emit_tag, record)
|
37
29
|
|
38
30
|
# implemented to immediate call post method in this loop, because graphite-api.gem has the buffers.
|
39
|
-
post(metrics, time)
|
31
|
+
Graphite.post(metrics, time)
|
40
32
|
end
|
41
33
|
|
42
34
|
end
|
43
35
|
|
44
|
-
def format_metrics(tag, record)
|
45
|
-
metrics = {}
|
46
|
-
metrics[@monitoring_key + "." + tag] = 1
|
47
|
-
metrics
|
48
|
-
end
|
49
|
-
|
50
|
-
def post(metric, time)
|
51
|
-
trial ||= 1
|
52
|
-
@client.metrics(metric, time)
|
53
|
-
log.warn("Sending metrics: #{metric}")
|
54
|
-
rescue Errno::ETIMEDOUT
|
55
|
-
# after long periods with nothing emitted, the connection will be closed and result in timeout
|
56
|
-
if trial <= @max_retries
|
57
|
-
log.warn "out_graphite: connection timeout to #{@host}:#{@port}. Reconnecting... "
|
58
|
-
trial += 1
|
59
|
-
connect_client!
|
60
|
-
retry
|
61
|
-
else
|
62
|
-
log.error "out_graphite: ERROR: connection timeout to #{@host}:#{@port}. Exceeded max_retries #{@max_retries}"
|
63
|
-
end
|
64
|
-
rescue Errno::ECONNREFUSED
|
65
|
-
log.warn "out_graphite: connection refused by #{@host}:#{@port}"
|
66
|
-
rescue SocketError => se
|
67
|
-
log.warn "out_graphite: socket error by #{@host}:#{@port} :#{se}"
|
68
|
-
rescue StandardError => e
|
69
|
-
log.error "out_graphite: ERROR: #{e}"
|
70
|
-
end
|
71
|
-
|
72
|
-
def connect_client!
|
73
|
-
options = {
|
74
|
-
# Required: valid URI {udp,tcp}://host:port/?timeout=seconds
|
75
|
-
graphite: "tcp://#{@host}:#{@port}",
|
76
|
-
|
77
|
-
# Optional: results are aggregated in 60 seconds slices ( default is 60 )
|
78
|
-
slice: 30,
|
79
|
-
|
80
|
-
# Optional: send to graphite every 60 seconds ( default is 0 - direct send )
|
81
|
-
interval: 30,
|
82
|
-
|
83
|
-
# Optional: set the max age in seconds for records reanimation ( default is 12 hours )
|
84
|
-
cache: 4 * 60 * 60,
|
85
|
-
}
|
86
|
-
@client = GraphiteAPI.new options
|
87
|
-
GraphiteAPI::Logger.init level: :debug
|
88
|
-
log.info("starting client")
|
89
|
-
end
|
90
36
|
end
|
91
37
|
end
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adp-fluent-plugin-graphite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Aleksander Dudek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 3.2.0
|
69
69
|
description: fluentd output plugin to send metrics to graphite
|
70
|
-
email:
|
70
|
+
email: adudek4@gmail.com
|
71
71
|
executables: []
|
72
72
|
extensions: []
|
73
73
|
extra_rdoc_files: []
|
@@ -79,10 +79,12 @@ 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
|
85
|
-
homepage:
|
87
|
+
homepage: ''
|
86
88
|
licenses:
|
87
89
|
- MIT
|
88
90
|
metadata: {}
|