fluent-plugin-light-core 0.1.9 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2433cbe7616d4740d7722d4438d18c91aa599db380962943e368af9277b3cd2c
4
- data.tar.gz: f8cb6f8a1f512b55b4d6340101363ad88c536f8983c9cbe7a644ab1cbc25f325
3
+ metadata.gz: b9273e4882e6e92ba31a9df62ba09b504368b4e1f206c0ab001ee0c92bac71cc
4
+ data.tar.gz: 14931871d7144232d2fd780c027567105bfca30f90647d8708aaf5591eba5107
5
5
  SHA512:
6
- metadata.gz: '08df5f1170b4f9f23e24c05883154af18d74146afaa8f3eca8e96b5d462d241a2115c6ea3fd424cf4da070d86e4bf4ff64d0bf1c637c3d4f20a691c81793fbe1'
7
- data.tar.gz: 69bbf8f5dc12be010404a76214576324febb1ae1cba9781279641f0b29e9362e7f3abc0a19daeb2876c30d84bb86f76305a7f3b0a983765831c3e386de6b7791
6
+ metadata.gz: 2ac5fc0b4586140102a7ae52127c7a5c0b79d38cab433495c5c8120ce7a33cec14d61f0b8460ab7a30bf5c28860f694c754a901f5d600f3928d091ab18d676e0
7
+ data.tar.gz: 3d7548b244d8bb8d11325963c21fe19ce022f7018b260cd5e46b1eca3a0e02daad585d1df51ce88fe940b63b461f26b25589dd77764b1af885236bbec3d8eeaa
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
+
5
+ gem "sentry-ruby"
@@ -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.1.9"
6
+ spec.version = "0.2.0"
7
7
  spec.authors = ["LIN LI"]
8
8
  spec.email = ["l.li@alphabets.cn"]
9
9
 
@@ -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 :notice, :bool, default: false
27
- config_param :port, :integer, default: 7000
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,35 @@ 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: 3000
37
+ config_param :lb_code, :array, default: ['400', '500'], value_type: :string
38
+ config_param :lb_elapsed, :float, default: 3
40
39
 
41
40
  # MongoDB 异常 settings
42
41
  config_param :mongo_severity, :array, default: ['F', 'E'], value_type: :string
43
42
  config_param :mongo_querytime, :float, default: 100
44
43
 
45
- # 初始化UDP实例
44
+ # 初始化 Sentry
46
45
  def start
47
46
  super
48
47
 
49
- if @notice
50
- log.info('init udp connection')
51
- @udp = UDPSocket.open()
52
- @udp.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, 1)
48
+ if @sentry
49
+ log.info('init sentry')
50
+ Sentry.init do |config|
51
+ config.dsn = @sentry_dsn
52
+
53
+ # To activate performance monitoring, set one of these options.
54
+ # We recommend adjusting the value in production:
55
+ config.traces_sample_rate = 1
56
+
57
+ # config.background_worker_threads = 2
58
+ config.transport.timeout = 10
59
+ config.transport.open_timeout = 10
60
+ end
53
61
  end
54
62
  end
55
63
 
56
- # 清理UDP连接
64
+ # 清理
57
65
  def shutdown
58
-
59
- if @notice
60
- log.info('close udp connection')
61
- @udp.close if @udp
62
- end
63
-
64
66
  super
65
67
  end
66
68
 
@@ -283,15 +285,18 @@ module Fluent
283
285
  # 确认是否发送通知
284
286
  def notice(tag, record)
285
287
 
286
- unless @notice
288
+ unless @sentry
287
289
  return record
288
290
  end
289
291
 
290
292
  if tag == 'app'
293
+
294
+ # 未使用
291
295
  if @app_stream && record['stream']
292
296
  send(record) if record['stream'] == @app_stream
293
297
  end
294
298
 
299
+ # 未使用
295
300
  if @app_message.length > 0 && record['message']
296
301
  @app_message.each do |pattern|
297
302
  if pattern.match(record['message'])
@@ -302,11 +307,13 @@ module Fluent
302
307
  end
303
308
 
304
309
  if @app_status.length > 0 && record['status']
305
- send(record) if @app_status.include?(record['status'])
310
+ message = 'Status code abnormal : ' + record['url']
311
+ send(tag, message, record) if @app_status.include?(record['status'])
306
312
  end
307
313
 
308
314
  if @app_elapsed > 0 && record['elapsed']
309
- send(record) if record['elapsed'].to_f > @app_elapsed
315
+ message = 'Slow process : ' + record['url']
316
+ send(tag, message, record) if record['elapsed'].to_f >= @app_elapsed
310
317
  end
311
318
 
312
319
  return record
@@ -314,15 +321,17 @@ module Fluent
314
321
 
315
322
  if tag == 'lb'
316
323
  if @lb_stream && record['stream']
317
- send(record) if record['stream'] == @lb_stream
324
+ send(tag, 'Stderror', record) if record['stream'] == @lb_stream
318
325
  end
319
326
 
320
327
  if @lb_code.length > 0 && record['code']
321
- send(record) if @lb_code.include?(record['code'])
328
+ message = 'Status code abnormal : ' + record['path']
329
+ send(tag, message, record) if @lb_code.include?(record['code'])
322
330
  end
323
331
 
324
332
  if @lb_elapsed > 0 && record['elapsed']
325
- send(record) if record['elapsed'].to_f > @lb_elapsed
333
+ message = 'Slow request : ' + record['path']
334
+ send(tag, message, record) if record['elapsed'].to_f >= @lb_elapsed
326
335
  end
327
336
 
328
337
  return record
@@ -330,11 +339,14 @@ module Fluent
330
339
 
331
340
  if tag == 'mongo'
332
341
  if @mongo_severity.length > 0 && record['severity']
333
- send(record) if @mongo_severity.include?(record['severity'])
342
+ message = 'Severity level abnormal : ' + record['severity']
343
+ send(tag, message, record) if @mongo_severity.include?(record['severity'])
334
344
  end
335
345
 
336
346
  if @mongo_querytime > 0 && record['querytime']
337
- send(record) if record['querytime'].to_f > @mongo_querytime
347
+ message = 'Slow query'
348
+ message = message + ' : ' + record['collection'] if record['collection']
349
+ send(tag, message, record) if record['querytime'].to_f >= @mongo_querytime
338
350
  end
339
351
 
340
352
  return record
@@ -345,17 +357,9 @@ module Fluent
345
357
  end
346
358
 
347
359
  # 发送UDP请求
348
- def send(record)
349
-
350
- log.info('send udp notice', record)
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))
360
+ def send(tag, message, record)
361
+ log.debug('send udp notice')
362
+ Sentry.capture_message(message, :extra => record, :tags => {'log' => tag})
359
363
  end
360
364
 
361
365
  # 转数字
@@ -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
@@ -79,6 +79,15 @@
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
+ app_status 500
90
+ app_elapsed 5
82
91
  </filter>
83
92
 
84
93
  # <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.1.9
4
+ version: 0.2.0
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-01-28 00:00:00.000000000 Z
11
+ date: 2021-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler