fluent-plugin-light-core 0.1.9 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/fluent-plugin-light-core.gemspec +2 -1
- data/lib/fluent/plugin/filter_light_core.rb +72 -98
- data/sample/README.md +10 -0
- data/sample/source.conf +10 -0
- metadata +22 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a553d56fc47ba8c7ae49428e3d60a5180bb90a9d3b355ebec22b6983265249a9
|
4
|
+
data.tar.gz: b27775457e6b5cea4f80a6d83095460ef2d59087648ef683331615a90e4a2fce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69e2cf2089fb5be1cc62fcdbe86498b1711c0e5bea39767044d9b3e2e853026ec9a0f122609c05b79e57e58f6d74f7fc924563e56526d9ecdde61ec4631dde27
|
7
|
+
data.tar.gz: e384dadbc0567ac19f7013209aa43441981c0aedb85bfa9381b86118422956b839d218b6a2b8083dc5ae9af93ed503d8ecc181afae6de952e148fff1d640bf4c
|
data/Gemfile
CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |spec|
|
5
5
|
spec.name = "fluent-plugin-light-core"
|
6
|
-
spec.version = "0.
|
6
|
+
spec.version = "0.2.3"
|
7
7
|
spec.authors = ["LIN LI"]
|
8
8
|
spec.email = ["l.li@alphabets.cn"]
|
9
9
|
|
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency "rake", "~> 12.0"
|
25
25
|
spec.add_development_dependency "test-unit", "~> 3.0"
|
26
26
|
spec.add_runtime_dependency "fluentd", [">= 0.14.10", "< 2"]
|
27
|
+
spec.add_runtime_dependency "sentry-ruby", [">= 4.1.5", "< 5"]
|
27
28
|
end
|
@@ -14,8 +14,8 @@
|
|
14
14
|
# limitations under the License.
|
15
15
|
|
16
16
|
require 'fluent/plugin/filter'
|
17
|
-
require 'socket'
|
18
17
|
require 'json'
|
18
|
+
require 'sentry-ruby'
|
19
19
|
|
20
20
|
module Fluent
|
21
21
|
module Plugin
|
@@ -23,9 +23,8 @@ module Fluent
|
|
23
23
|
Fluent::Plugin.register_filter('light_core', self)
|
24
24
|
|
25
25
|
# 通知相关配置
|
26
|
-
config_param :
|
27
|
-
config_param :
|
28
|
-
config_param :host, :string, default: '255.255.255.255'
|
26
|
+
config_param :sentry, :bool, default: false
|
27
|
+
config_param :sentry_dsn, :string, default: ''
|
29
28
|
|
30
29
|
# Application 异常 settings
|
31
30
|
config_param :app_stream, :string, default: 'stderr'
|
@@ -35,32 +34,36 @@ module Fluent
|
|
35
34
|
|
36
35
|
# Nginx 异常 settings
|
37
36
|
config_param :lb_stream, :string, default: 'stderr'
|
38
|
-
config_param :lb_code, :array, default: ['500'], value_type: :string
|
39
|
-
config_param :lb_elapsed, :float, default:
|
37
|
+
config_param :lb_code, :array, default: ['400', '500'], value_type: :string
|
38
|
+
config_param :lb_elapsed, :float, default: 3
|
39
|
+
config_param :lb_ignore, :array, default: [], value_type: :string
|
40
40
|
|
41
41
|
# MongoDB 异常 settings
|
42
42
|
config_param :mongo_severity, :array, default: ['F', 'E'], value_type: :string
|
43
43
|
config_param :mongo_querytime, :float, default: 100
|
44
44
|
|
45
|
-
# 初始化
|
45
|
+
# 初始化 Sentry
|
46
46
|
def start
|
47
47
|
super
|
48
48
|
|
49
|
-
if @
|
50
|
-
log.info('init
|
51
|
-
|
52
|
-
|
49
|
+
if @sentry
|
50
|
+
log.info('init sentry')
|
51
|
+
Sentry.init do |config|
|
52
|
+
config.dsn = @sentry_dsn
|
53
|
+
|
54
|
+
# To activate performance monitoring, set one of these options.
|
55
|
+
# We recommend adjusting the value in production:
|
56
|
+
config.traces_sample_rate = 1
|
57
|
+
|
58
|
+
# config.background_worker_threads = 2
|
59
|
+
config.transport.timeout = 10
|
60
|
+
config.transport.open_timeout = 10
|
61
|
+
end
|
53
62
|
end
|
54
63
|
end
|
55
64
|
|
56
|
-
# 清理
|
65
|
+
# 清理
|
57
66
|
def shutdown
|
58
|
-
|
59
|
-
if @notice
|
60
|
-
log.info('close udp connection')
|
61
|
-
@udp.close if @udp
|
62
|
-
end
|
63
|
-
|
64
67
|
super
|
65
68
|
end
|
66
69
|
|
@@ -128,9 +131,9 @@ module Fluent
|
|
128
131
|
record['method'] = item[:method]
|
129
132
|
record['url'] = item[:url]
|
130
133
|
record['status'] = item[:status]
|
131
|
-
record['size'] =
|
134
|
+
record['size'] = str_to_num(item[:size])
|
132
135
|
record['uid'] = item[:uid]
|
133
|
-
record['elapsed'] =
|
136
|
+
record['elapsed'] = str_to_num(item[:elapsed])
|
134
137
|
record['addr'] = item[:addr].gsub(/\n$/, '')
|
135
138
|
|
136
139
|
return record
|
@@ -167,10 +170,10 @@ module Fluent
|
|
167
170
|
record['method'] = item[:method]
|
168
171
|
record['path'] = item[:path]
|
169
172
|
record['code'] = item[:code]
|
170
|
-
record['size'] =
|
173
|
+
record['size'] = str_to_num(item[:size])
|
171
174
|
record['referer'] = item[:referer]
|
172
175
|
record['agent'] = item[:agent]
|
173
|
-
record['elapsed'] =
|
176
|
+
record['elapsed'] = str_to_num(item[:elapsed])
|
174
177
|
record['requestid'] = item[:requestid]
|
175
178
|
record['sessionid'] = item[:sessionid]
|
176
179
|
|
@@ -181,7 +184,7 @@ module Fluent
|
|
181
184
|
if /^\d{4}\/\d{2}\/\d{2} \d{2}:\d{2}:\d{2} \[error\]/.match(log)
|
182
185
|
item = /^(?<time>[^ ]+ [^ ]+) \[(?<level>.*)\] (?<pid>\d*)#(?<tid>[^:]*): \*(?<cid>\d*) (?<message>.*)$/.match(log)
|
183
186
|
|
184
|
-
record['time'] =
|
187
|
+
record['time'] = record['ctime']
|
185
188
|
record['level'] = item[:level]
|
186
189
|
record['message'] = item[:message]
|
187
190
|
record['process'] = item[:pid] # process id
|
@@ -222,107 +225,82 @@ module Fluent
|
|
222
225
|
record.delete('file')
|
223
226
|
record.delete('time')
|
224
227
|
|
225
|
-
#
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
if item[:querytime]
|
241
|
-
record['querytime'] = format_str(item[:querytime])
|
242
|
-
end
|
243
|
-
|
244
|
-
if item[:query]
|
245
|
-
record['command'] = item[:query]
|
246
|
-
query = /^command\s* (?<collection>[^ ]*) (?<command>.*)$/.match(item[:query])
|
247
|
-
unless query.nil?
|
248
|
-
record['collection'] = query[:collection]
|
249
|
-
record['command'] = query[:command]
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
return record
|
254
|
-
else
|
255
|
-
|
256
|
-
# 版本4.4开始,默认日志为json格式
|
257
|
-
item = JSON.parse(log)
|
258
|
-
record['time'] = item['t']['$date']
|
259
|
-
record['severity'] = item['s']
|
260
|
-
record['component'] = item['c']
|
261
|
-
record['context'] = item['ctx']
|
262
|
-
record['identifier'] = item['id']
|
263
|
-
record['message'] = item['msg']
|
264
|
-
|
265
|
-
attributes = item['attr']
|
266
|
-
if attributes
|
267
|
-
record['querytime'] = attributes['durationMillis']
|
268
|
-
record['collection'] = attributes['ns']
|
269
|
-
record['command'] = attributes['command']
|
270
|
-
record['attr'] = attributes
|
271
|
-
end
|
272
|
-
|
273
|
-
record['tags'] = item['tags']
|
274
|
-
record['truncated'] = item['truncated']
|
275
|
-
record['size'] = item['size']
|
276
|
-
|
277
|
-
return record
|
228
|
+
# 版本4.4开始,默认日志为json格式
|
229
|
+
item = JSON.parse(log)
|
230
|
+
record['time'] = item['t']['$date']
|
231
|
+
record['severity'] = item['s']
|
232
|
+
record['component'] = item['c']
|
233
|
+
record['context'] = item['ctx']
|
234
|
+
record['identifier'] = item['id']
|
235
|
+
record['message'] = item['msg']
|
236
|
+
|
237
|
+
attributes = item['attr']
|
238
|
+
if attributes
|
239
|
+
record['querytime'] = attributes['durationMillis']
|
240
|
+
record['collection'] = attributes['ns']
|
241
|
+
record['command'] = attributes['command']
|
242
|
+
record['attr'] = attributes
|
278
243
|
end
|
279
244
|
|
245
|
+
record['tags'] = item['tags']
|
246
|
+
record['truncated'] = item['truncated']
|
247
|
+
record['size'] = item['size']
|
280
248
|
record
|
281
249
|
end
|
282
250
|
|
283
251
|
# 确认是否发送通知
|
284
252
|
def notice(tag, record)
|
285
253
|
|
286
|
-
unless @
|
254
|
+
unless @sentry
|
287
255
|
return record
|
288
256
|
end
|
289
257
|
|
290
258
|
if tag == 'app'
|
259
|
+
|
291
260
|
if @app_stream && record['stream']
|
292
|
-
send(record) if record['stream'] == @app_stream
|
261
|
+
send(tag, record['message'], record) if record['stream'] == @app_stream
|
293
262
|
end
|
294
263
|
|
295
264
|
if @app_message.length > 0 && record['message']
|
296
265
|
@app_message.each do |pattern|
|
297
266
|
if pattern.match(record['message'])
|
298
|
-
send(record)
|
267
|
+
send(tag, record['message'], record)
|
299
268
|
break
|
300
269
|
end
|
301
270
|
end
|
302
271
|
end
|
303
272
|
|
304
273
|
if @app_status.length > 0 && record['status']
|
305
|
-
|
274
|
+
message = 'Status code abnormal : ' + record['url']
|
275
|
+
send(tag, message, record) if @app_status.include?(record['status'])
|
306
276
|
end
|
307
277
|
|
308
278
|
if @app_elapsed > 0 && record['elapsed']
|
309
|
-
|
279
|
+
message = 'Slow process : ' + record['url']
|
280
|
+
send(tag, message, record) if record['elapsed'].to_f >= @app_elapsed
|
310
281
|
end
|
311
282
|
|
312
283
|
return record
|
313
284
|
end
|
314
285
|
|
315
286
|
if tag == 'lb'
|
287
|
+
|
288
|
+
if @lb_ignore && record['path'] && @lb_ignore.include?(record['path'])
|
289
|
+
return record
|
290
|
+
end
|
291
|
+
|
316
292
|
if @lb_stream && record['stream']
|
317
|
-
send(record) if record['stream'] == @lb_stream
|
293
|
+
send(tag, 'Stderror', record) if record['stream'] == @lb_stream
|
318
294
|
end
|
319
295
|
|
320
296
|
if @lb_code.length > 0 && record['code']
|
321
|
-
|
297
|
+
message = 'Status code abnormal : ' + record['path']
|
298
|
+
send(tag, message, record) if @lb_code.include?(record['code'])
|
322
299
|
end
|
323
300
|
|
324
301
|
if @lb_elapsed > 0 && record['elapsed']
|
325
|
-
|
302
|
+
message = 'Slow request : ' + record['path']
|
303
|
+
send(tag, message, record) if record['elapsed'].to_f >= @lb_elapsed
|
326
304
|
end
|
327
305
|
|
328
306
|
return record
|
@@ -330,11 +308,14 @@ module Fluent
|
|
330
308
|
|
331
309
|
if tag == 'mongo'
|
332
310
|
if @mongo_severity.length > 0 && record['severity']
|
333
|
-
|
311
|
+
message = 'Severity level abnormal : ' + record['severity']
|
312
|
+
send(tag, message, record) if @mongo_severity.include?(record['severity'])
|
334
313
|
end
|
335
314
|
|
336
315
|
if @mongo_querytime > 0 && record['querytime']
|
337
|
-
|
316
|
+
message = 'Slow query'
|
317
|
+
message = message + ' : ' + record['collection'] if record['collection']
|
318
|
+
send(tag, message, record) if record['querytime'].to_f >= @mongo_querytime
|
338
319
|
end
|
339
320
|
|
340
321
|
return record
|
@@ -345,21 +326,14 @@ module Fluent
|
|
345
326
|
end
|
346
327
|
|
347
328
|
# 发送UDP请求
|
348
|
-
def send(record)
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
data = {
|
353
|
-
:query => '/api/log/notice',
|
354
|
-
:params => {
|
355
|
-
:data => record
|
356
|
-
}
|
357
|
-
}
|
358
|
-
@udp.send(data.to_json, 0, Socket.pack_sockaddr_in(@port, @host))
|
329
|
+
def send(tag, message, record)
|
330
|
+
log.debug('send udp notice')
|
331
|
+
Sentry.capture_message(message, :extra => record, :tags => {'log' => tag})
|
359
332
|
end
|
360
333
|
|
361
334
|
# 转数字
|
362
|
-
def
|
335
|
+
def str_to_num(str)
|
336
|
+
return 0 if (str == '-')
|
363
337
|
return str.to_i if (str =~ /^\d+$/)
|
364
338
|
return str.to_f if (str =~ /^\d+\.\d+$/)
|
365
339
|
str
|
data/sample/README.md
CHANGED
@@ -32,3 +32,13 @@ Initialized empty Git repository in /Users/lilin/developer/light/fluent-plugin-l
|
|
32
32
|
|
33
33
|
% rm -f sample/*.pos
|
34
34
|
% fluentd -c sample/source.conf -p lib/fluent/plugin
|
35
|
+
|
36
|
+
## 添加 sentry 依赖
|
37
|
+
|
38
|
+
- 编辑Gemfile
|
39
|
+
|
40
|
+
gem "sentry-ruby"
|
41
|
+
|
42
|
+
- 安装依赖
|
43
|
+
|
44
|
+
gem install sentry-ruby
|
data/sample/source.conf
CHANGED
@@ -79,6 +79,16 @@
|
|
79
79
|
|
80
80
|
<filter **>
|
81
81
|
@type light_core
|
82
|
+
sentry true
|
83
|
+
sentry_dsn https://4447403a2a86437491d307ceb72898e5@sentry.zf.link/4
|
84
|
+
mongo_querytime 300
|
85
|
+
mongo_severity F,E
|
86
|
+
lb_stream stderr
|
87
|
+
lb_code 400,500
|
88
|
+
lb_elapsed 5
|
89
|
+
lb_ignore /api/environment/list,/api/certificate/list?condition%5Bkind%5D=SSL
|
90
|
+
app_status 500
|
91
|
+
app_elapsed 5
|
82
92
|
</filter>
|
83
93
|
|
84
94
|
# <match app>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-light-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- LIN LI
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -72,6 +72,26 @@ dependencies:
|
|
72
72
|
- - "<"
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '2'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: sentry-ruby
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 4.1.5
|
82
|
+
- - "<"
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '5'
|
85
|
+
type: :runtime
|
86
|
+
prerelease: false
|
87
|
+
version_requirements: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: 4.1.5
|
92
|
+
- - "<"
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '5'
|
75
95
|
description: light core fluent plugin. support mongodb, nginx and application
|
76
96
|
email:
|
77
97
|
- l.li@alphabets.cn
|