fluent-plugin-mongo-slow-query 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fluent/plugin/in_mongo_slow_query.rb +43 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 284e26c6dc167bed1678ea14f4efb320be3148e5
|
4
|
+
data.tar.gz: a50274330aa6b8fe11eb052d4fa2414cf095ba1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdc3f9ef96cc3e558831772744e8709d10a6e1b42df55435a2a2bf732c67f926acefbdda555372b969c3d9634508fc688ad144d8059912a142fa8a98e124f865
|
7
|
+
data.tar.gz: da2a2a1938f10227c0a62f2106d378ea69ced0c930a07f4eebf7cc62d77c0fb08abe73c73fa8982430f6e75561d119de834d50df8843e7962b3c5fce39985c28
|
@@ -10,16 +10,27 @@ module Fluent
|
|
10
10
|
# 'conf' is a Hash that includes configuration parameters.
|
11
11
|
# If the configuration is invalid, raise Fluent::ConfigError.
|
12
12
|
def configure(conf)
|
13
|
-
unless conf.has_key?("format")
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
13
|
+
#unless conf.has_key?("format")
|
14
|
+
# conf["format"] = '/(?<time>.*) \[\w+\] (?<op>[^ ]+) (?<ns>[^ ]+) (?<detail>((query: (?<query>{.+}) update: {.*})|(query: (?<query>{.+})))) .* (?<ms>\d+)ms/'
|
15
|
+
# $log.warn "load default format: ", conf["format"]
|
16
|
+
#end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
# load default format that degisned for MongoDB
|
19
|
+
conf["format"] = '/(?<time>.*) \[\w+\] (?<op>[^ ]+) (?<ns>[^ ]+) ((?<detail>(query: (?<query>\{.+\}) update: \{.*\}))|((?<detail>(query: (?<query>\{.+\}))) planSummary: .*)|((?<detail>query: (?<query>\{.+\})))) .* (?<ms>\d+)ms/'
|
20
|
+
|
21
|
+
# not set "time_format"
|
22
|
+
# default use Ruby's DateTime.parse() to pase time
|
23
|
+
#
|
24
|
+
# be compatible for v2.2, 2.4 and 2.6
|
25
|
+
# difference of time format
|
26
|
+
# 2.2: Wed Sep 17 10:00:00 [conn] ...
|
27
|
+
# 2.4: Wed Sep 17 10:00:00.123 [conn] ...
|
28
|
+
# 2.6: 2014-09-17T10:00:43.506+0800 [conn] ...
|
29
|
+
#unless conf.has_key?("time_format")
|
30
|
+
# #conf["time_format"] = '%a %b %d %H:%M:%S'
|
31
|
+
# #conf["time_format"] = '%a %b %d %H:%M:%S.%L'
|
32
|
+
# #$log.warn "load default time_format: ", conf["time_format"]
|
33
|
+
#end
|
23
34
|
super
|
24
35
|
end
|
25
36
|
|
@@ -30,10 +41,9 @@ module Fluent
|
|
30
41
|
line.chomp! # remove \n
|
31
42
|
time, record = parse_line(line)
|
32
43
|
if time && record
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
44
|
+
record["query"] = get_query_prototype(record["query"])
|
45
|
+
record["ms"] = record["ms"].to_i
|
46
|
+
record["ts"] = time
|
37
47
|
#if record.has_key?("update")
|
38
48
|
# record["update"] = get_query_prototype(record["update"])
|
39
49
|
#end
|
@@ -89,7 +99,17 @@ module Fluent
|
|
89
99
|
|
90
100
|
# convert query to JSON
|
91
101
|
def to_json(query)
|
92
|
-
res = query
|
102
|
+
res = query
|
103
|
+
# conversion for fieldname
|
104
|
+
res = res.gsub(/( [^ ]+?: )/) {|fieldname| fieldname_format(fieldname)}
|
105
|
+
# conversion for ObjectId
|
106
|
+
res = res.gsub(/ObjectId\([^ ]+?\)/) {|objectid| to_string(objectid)}
|
107
|
+
# conversion for Timestamp
|
108
|
+
res = res.gsub(/Timestamp \d+\|\d+/) {|timestamp| to_string(timestamp)}
|
109
|
+
# conversion for Date
|
110
|
+
res = res.gsub(/new Date\(\d+\)/) {|date| to_string(date)}
|
111
|
+
# filter regex
|
112
|
+
res = res.gsub(/\/\^.*\//) {|pattern| to_string(pattern)}
|
93
113
|
return res
|
94
114
|
end
|
95
115
|
|
@@ -98,5 +118,14 @@ module Fluent
|
|
98
118
|
def fieldname_format(fieldname)
|
99
119
|
return ' "%s": ' % fieldname.strip.chomp(':')
|
100
120
|
end
|
121
|
+
|
122
|
+
# convert value of special type to string
|
123
|
+
# so that convert query to json
|
124
|
+
def to_string(str)
|
125
|
+
res = str
|
126
|
+
res = res.gsub(/"/, '\"')
|
127
|
+
res = '"%s"' % res
|
128
|
+
return res
|
129
|
+
end
|
101
130
|
end
|
102
131
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-mongo-slow-query
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- caosiyang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: fluent plugin for mongo slow query
|
14
14
|
email: csy3228@gmail.com
|