adp-fluent-plugin-graphite 0.0.16 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/adp-fluent-plugin-graphite.gemspec +4 -4
- data/lib/fluent/plugin/filter_graphite.rb +28 -0
- data/lib/fluent/plugin/graphite.rb +75 -0
- data/lib/fluent/plugin/out_graphite.rb +7 -65
- 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: dcb0b99995de71b515fd3b5934589d95af6cfdbdbca9ccac9ac6ac349720d02c
|
4
|
+
data.tar.gz: 384393b27c068712191daeb631a16fb5c7f9ef641bad7f8e396ce7733283569f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad9e87463588d24c7fcad9b90d54993aecf05269284c3e3b740f66d038e96c9e28468de7ee58cdc0d73455fd7762203eaa1e416f2e60416e1ecd1ee9b542b559
|
7
|
+
data.tar.gz: 4a58e1b33b50e3c38de527a6a97c7e5a649b5a77955a9c4783054db6f1aaa10c26703428078f9acf5082546a980ed156ca702bfcfff3bcd9b7fc6ef58c6cc9d7
|
@@ -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.0
|
7
|
-
gem.authors = ['
|
8
|
-
gem.email = '
|
9
|
-
gem.homepage = '
|
6
|
+
gem.version = '0.1.0'
|
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,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,95 +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: 60,
|
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
|
-
# Optional: The default aggregation method for multiple reports in the same slice (default is :sum).
|
87
|
-
# Possible options: :sum, :avg, :replace
|
88
|
-
default_aggregation_method: :avg
|
89
|
-
}
|
90
|
-
@client = GraphiteAPI.new options
|
91
|
-
GraphiteAPI::Logger.init level: :debug
|
92
|
-
log.info("starting client")
|
93
|
-
end
|
94
36
|
end
|
95
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.0
|
4
|
+
version: 0.1.0
|
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: {}
|