fluent-plugin-light-core 0.1.2 → 0.1.3
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/fluent-plugin-light-core.gemspec +1 -1
- data/lib/fluent/plugin/filter_light_core.rb +134 -7
- data/sample/README.md +1 -0
- data/sample/udpsample.rb +20 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 262f7c2b69259e409b93285c4138386a24d7ee2d12d81f120ef1306875d0d701
|
4
|
+
data.tar.gz: 19ecb1abd1e754ffe2da66f72c8cb211fe81aa5a4e3543c742f63d6ee121a474
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a39111482eb7fcd051f14f92d4a6f062df5f9673f0a474c2c26ea5c73ba25074a2e13237ae3dc9c67e9ec2743009c4cc59a63476dd20a98883151fb691e62090
|
7
|
+
data.tar.gz: de9645e74a662f9b5be93e4bdfb7141f8e473c27dff352755f7dca683ced2d505a2a7188270ef5a0a540e1a15f1bce8f5fcb15eaa963efeca89994397eb56abb
|
@@ -13,25 +13,73 @@
|
|
13
13
|
# See the License for the specific language governing permissions and
|
14
14
|
# limitations under the License.
|
15
15
|
|
16
|
-
require
|
16
|
+
require 'fluent/plugin/filter'
|
17
|
+
require 'socket'
|
18
|
+
require 'json'
|
17
19
|
|
18
20
|
module Fluent
|
19
21
|
module Plugin
|
20
22
|
class LightCoreFilter < Fluent::Plugin::Filter
|
21
|
-
Fluent::Plugin.register_filter(
|
23
|
+
Fluent::Plugin.register_filter('light_core', self)
|
24
|
+
|
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'
|
29
|
+
|
30
|
+
# Application 异常 settings
|
31
|
+
config_param :app_stream, :string, default: 'stderr'
|
32
|
+
config_param :app_message, :array, default: [], value_type: :regexp
|
33
|
+
config_param :app_status, :array, default: ['500'], value_type: :string
|
34
|
+
config_param :app_elapsed, :float, default: 2000
|
35
|
+
|
36
|
+
# Nginx 异常 settings
|
37
|
+
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
|
40
|
+
|
41
|
+
# MongoDB 异常 settings
|
42
|
+
config_param :mongo_severity, :array, default: ['F', 'E'], value_type: :string
|
43
|
+
config_param :mongo_querytime, :float, default: 100
|
44
|
+
|
45
|
+
# 初始化UDP实例
|
46
|
+
def start
|
47
|
+
super
|
48
|
+
|
49
|
+
if @notice
|
50
|
+
log.info('init udp connection')
|
51
|
+
@udp = UDPSocket.open()
|
52
|
+
@udp.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, 1)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# 清理UDP连接
|
57
|
+
def shutdown
|
58
|
+
|
59
|
+
if @notice
|
60
|
+
log.info('close udp connection')
|
61
|
+
@udp.close if @udp
|
62
|
+
end
|
63
|
+
|
64
|
+
super
|
65
|
+
end
|
22
66
|
|
67
|
+
# 主处理
|
23
68
|
def filter(tag, time, record)
|
24
69
|
|
25
70
|
if tag == 'app'
|
26
|
-
|
71
|
+
record = filter_app(tag, time, record)
|
72
|
+
return notice('app', record)
|
27
73
|
end
|
28
74
|
|
29
75
|
if ['lb', 'hub'].include? tag
|
30
|
-
|
76
|
+
record = filter_lb(tag, time, record)
|
77
|
+
return notice('lb', record)
|
31
78
|
end
|
32
79
|
|
33
80
|
if ['mongo', 'secondary', 'arbiter'].include? tag
|
34
|
-
|
81
|
+
record = filter_mongo(tag, time, record)
|
82
|
+
return notice('mongo', record)
|
35
83
|
end
|
36
84
|
|
37
85
|
record
|
@@ -109,7 +157,7 @@ module Fluent
|
|
109
157
|
|
110
158
|
# access log
|
111
159
|
if /^[^ ]+ [^ ]+ [^ ]+ \[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+\d{2}:\d{2}\]/.match(log)
|
112
|
-
item = /^(?<remote>[^ ]*) (?<host>[^ ]*) (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)" "(?<forwarder>[^\"]*)")?/.match(log)
|
160
|
+
item = /^(?<remote>[^ ]*) (?<host>[^ ]*) (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)" "(?<forwarder>[^\"]*)" "(?<elapsed>[^\"]*)")?/.match(log)
|
113
161
|
|
114
162
|
record['remote'] = item[:remote]
|
115
163
|
record['host'] = item[:host]
|
@@ -122,6 +170,7 @@ module Fluent
|
|
122
170
|
record['referer'] = item[:referer]
|
123
171
|
record['agent'] = item[:agent]
|
124
172
|
record['forwarder'] = item[:forwarder]
|
173
|
+
record['elapsed'] = item[:elapsed]
|
125
174
|
|
126
175
|
return record
|
127
176
|
end
|
@@ -173,7 +222,7 @@ module Fluent
|
|
173
222
|
|
174
223
|
if /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}\+\d{4} [A-Z]/.match(log)
|
175
224
|
|
176
|
-
item = /^(?<time>[^ ]*) (?<severity>[A-Z])\s* (?<component>(-|([^ ]*)))\s* \[(?<context>[^\]]*)\]\s* ((?<query>.*) (?<querytime>[\d\.]+(?=ms))|(?<message>.*))/.match(log)
|
225
|
+
item = /^(?<time>[^ ]*) (?<severity>[A-Z])\s* (?<component>(-|([^ ]*)))\s* \[(?<context>[^\]]*)\]\s* ((?<query>.*) protocol:op_query (?<querytime>[\d\.]+(?=ms))|(?<message>.*))/.match(log)
|
177
226
|
|
178
227
|
record['time'] = item[:time]
|
179
228
|
record['severity'] = item[:severity]
|
@@ -201,6 +250,84 @@ module Fluent
|
|
201
250
|
record
|
202
251
|
end
|
203
252
|
|
253
|
+
# 确认是否发送通知
|
254
|
+
def notice(tag, record)
|
255
|
+
|
256
|
+
unless @notice
|
257
|
+
return record
|
258
|
+
end
|
259
|
+
|
260
|
+
if tag == 'app'
|
261
|
+
if @app_stream && record['stream']
|
262
|
+
send(record) if record['stream'] == @app_stream
|
263
|
+
end
|
264
|
+
|
265
|
+
if @app_message.length > 0 && record['message']
|
266
|
+
@app_message.each do |pattern|
|
267
|
+
if pattern.match(record['message'])
|
268
|
+
send(record)
|
269
|
+
break
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
if @app_status.length > 0 && record['status']
|
275
|
+
send(record) if @app_status.include?(record['status'])
|
276
|
+
end
|
277
|
+
|
278
|
+
if @app_elapsed > 0 && record['elapsed']
|
279
|
+
send(record) if record['elapsed'].to_f > @app_elapsed
|
280
|
+
end
|
281
|
+
|
282
|
+
return record
|
283
|
+
end
|
284
|
+
|
285
|
+
if tag == 'lb'
|
286
|
+
if @lb_stream && record['stream']
|
287
|
+
send(record) if record['stream'] == @lb_stream
|
288
|
+
end
|
289
|
+
|
290
|
+
if @lb_code.length > 0 && record['code']
|
291
|
+
send(record) if @lb_code.include?(record['code'])
|
292
|
+
end
|
293
|
+
|
294
|
+
if @lb_elapsed > 0 && record['elapsed']
|
295
|
+
send(record) if record['elapsed'].to_f > @lb_elapsed
|
296
|
+
end
|
297
|
+
|
298
|
+
return record
|
299
|
+
end
|
300
|
+
|
301
|
+
if tag == 'mongo'
|
302
|
+
if @mongo_severity.length > 0 && record['severity']
|
303
|
+
send(record) if @mongo_severity.include?(record['severity'])
|
304
|
+
end
|
305
|
+
|
306
|
+
if @mongo_querytime > 0 && record['querytime']
|
307
|
+
send(record) if record['querytime'].to_f > @mongo_querytime
|
308
|
+
end
|
309
|
+
|
310
|
+
return record
|
311
|
+
end
|
312
|
+
|
313
|
+
record
|
314
|
+
|
315
|
+
end
|
316
|
+
|
317
|
+
# 发送UDP请求
|
318
|
+
def send(record)
|
319
|
+
|
320
|
+
log.info('send udp notice', record)
|
321
|
+
|
322
|
+
data = {
|
323
|
+
:query => '/api/log/notice',
|
324
|
+
:params => {
|
325
|
+
:data => record
|
326
|
+
}
|
327
|
+
}
|
328
|
+
@udp.send(data.to_json, 0, Socket.pack_sockaddr_in(@port, @host))
|
329
|
+
end
|
330
|
+
|
204
331
|
end
|
205
332
|
end
|
206
333
|
end
|
data/sample/README.md
CHANGED
data/sample/udpsample.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
require 'socket'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
udp = UDPSocket.open()
|
6
|
+
udp.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, 1)
|
7
|
+
udp_addr = Socket.pack_sockaddr_in(7000, '255.255.255.255')
|
8
|
+
|
9
|
+
data = {
|
10
|
+
:query => '/api/log/notice',
|
11
|
+
:params => {
|
12
|
+
:data => {:A => 'A'}
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
params = data.to_json
|
17
|
+
params = "{\"query\":\"/api/log/notice\",\"params\":{\"data\":{\"stream\":\"stdout\",\"environment\":\"Mac\",\"cid\":\"app-0c1b728705d8-f5fc78bc8-8rjfl\",\"cname\":\"0c1b728705d8\",\"ctime\":\"2020-09-20T06:00:53.516987008Z\",\"time\":\"2020-09-20T06:00:53.516\",\"component\":\"I\",\"method\":\"GET\",\"url\":\"/api/app/last?id=xundianxb&os=android\",\"status\":\"200\",\"size\":\"349\",\"uid\":\"-\",\"elapsed\":\"76.078\",\"addr\":\"::ffff:10.244.4.86\"}}}"
|
18
|
+
udp.send(params, 0, udp_addr)
|
19
|
+
|
20
|
+
udp.close
|
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.
|
4
|
+
version: 0.1.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: 2020-09
|
11
|
+
date: 2020-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -89,6 +89,7 @@ files:
|
|
89
89
|
- lib/fluent/plugin/filter_light_core.rb
|
90
90
|
- sample/README.md
|
91
91
|
- sample/source.conf
|
92
|
+
- sample/udpsample.rb
|
92
93
|
- test/helper.rb
|
93
94
|
- test/plugin/test_filter_light_core.rb
|
94
95
|
homepage: https://git.alphabets.cn/light/fluent-plugin-light-core
|