adp-fluent-plugin-graphite 0.0.19 → 0.1.3
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 +1 -1
- data/lib/fluent/plugin/filter_graphite.rb +31 -0
- data/lib/fluent/plugin/graphite.rb +75 -0
- data/lib/fluent/plugin/out_graphite.rb +3 -68
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b10efa44d94d4c13b3cacb907c15d7d5775b3a5c0ef10dfb81069d2ea69aeb34
|
4
|
+
data.tar.gz: ecd6691d95ce2e20647a60f90e7065345113a0a2059fe13fe4db1f65b3a15460
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 320fc2f809cb97b2a0992f801365a60e5fc63586e46d2f9f9a32fa98d18350998149c6e1418f19abd2b2446a764de8647106f86c4d022a80356e4dfca733c667
|
7
|
+
data.tar.gz: 5e497eb638eeeea3b6757a169ce23b37845f35f240cf555a9b5c79b449bf4c46dfacf27211a8d4419e0f675eec03eaf204cc98eb08e92fb7d479932cb81b1d9c
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'fluent/plugin/graphite'
|
2
|
+
require 'fluent/plugin/filter'
|
3
|
+
|
4
|
+
module Fluent::Plugin
|
5
|
+
class GraphiteFilter < Fluent::Plugin::Filter
|
6
|
+
Fluent::Plugin.register_filter('graphite', self)
|
7
|
+
include Fluent::Plugin::Graphite
|
8
|
+
|
9
|
+
config_param :host, :string
|
10
|
+
config_param :port, :integer, default: 2003
|
11
|
+
config_param :prefix, :string, default: 'adp-fluentd-agent'
|
12
|
+
config_param :monitoring_key, :string
|
13
|
+
config_param :max_retries, :integer, default: 3
|
14
|
+
config_param :log_level, :string, default: 'info'
|
15
|
+
|
16
|
+
def start
|
17
|
+
super
|
18
|
+
init_client(@log_level, @host, @port)
|
19
|
+
end
|
20
|
+
|
21
|
+
def configure(conf)
|
22
|
+
super
|
23
|
+
end
|
24
|
+
|
25
|
+
def filter(tag, time, record)
|
26
|
+
metrics = format_metrics(tag, record)
|
27
|
+
post(metrics, time)
|
28
|
+
record
|
29
|
+
end
|
30
|
+
end
|
31
|
+
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
|
-
|
18
|
+
init_client(@log_level, @host, @port)
|
23
19
|
end
|
24
20
|
|
25
21
|
def configure(conf)
|
@@ -37,66 +33,5 @@ module Fluent::Plugin
|
|
37
33
|
|
38
34
|
end
|
39
35
|
|
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}"
|
59
|
-
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
|
-
|
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
|
-
end
|
82
|
-
|
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.
|
4
|
+
version: 0.1.3
|
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
|