fluent-plugin-mongo-slow-query 0.0.5 → 0.1.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 +13 -5
- data/lib/fluent/plugin/in_mongo_slow_query.rb +59 -16
- metadata +10 -8
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YzJhM2VkMGUzMTA2ZTczMTg1ZjU1ZDVmNjdjYTI2MjUwOWI5OTBiOA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZjQxMDYwOWYyMzYzNWRiYjZhZjc4MjZlOTQyNTU3YWQ1YWVjNjlmZg==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OWQ4M2FmNDFmM2RhZTQ5Y2JmYTRlZWRiMmQ1NDU2OTg3ZDBlZWRjZGI5MGI1
|
10
|
+
ZjViZDlmNjcwZWM0Y2NkNDk1MDAxMGM1NTIxZDEyMjI0MWY4ZTU4ZWRhNzIw
|
11
|
+
YjIxN2Q4NDFjMGE3ZjFiOWZmODkyYTgwOGRjMDQ0ZTM3MDg5OWY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NDRmMTdiYWRhODE1ZGM4NjZmMDZiOTE0YWQwMmQwMWMwYjNiOTBiZTBkNGMx
|
14
|
+
MTRjZGQ5NzlmNGVhNDU4YzRmNTFkZWRjZjkyMTMxZWJhNjExZmU4MmYwZGYw
|
15
|
+
OGI2YjQyMmNhYzNhMDcxYjdiNzk0ZGUzZWM4NGE4ZWE4ZmUwMzU=
|
@@ -10,22 +10,18 @@ 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
|
-
#
|
14
|
-
|
15
|
-
# $log.warn "load default format: ", conf["format"]
|
16
|
-
#end
|
17
|
-
|
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/'
|
13
|
+
# load log format for MongoDB
|
14
|
+
conf["format"] = '/^(?<time>.*?)(?:\s+\w\s\w+\s*)? \[conn\d+\] (?<op>\w+) (?<ns>\S+) (?<detail>(?:(?:query: (?<query>\{.+\}) update: \{.*\})|(?:query: (?<query>\{.*\}) planSummary: \w+(?: \{.*\})?)|(?:query: (?<query>\{.*\}))|(?:command: \{.*\}))) (?<stat>.*) (?<ms>\d+)ms$/'
|
20
15
|
|
21
16
|
# not set "time_format"
|
22
17
|
# default use Ruby's DateTime.parse() to pase time
|
23
18
|
#
|
24
|
-
# be compatible for v2.2, 2.4 and
|
19
|
+
# be compatible for v2.2, 2.4, 2.6 and 3.0
|
25
20
|
# difference of time format
|
26
|
-
# 2.2: Wed Sep 17 10:00:00 [
|
27
|
-
# 2.4: Wed Sep 17 10:00:00.123 [
|
28
|
-
# 2.6: 2014-09-17T10:00:43.506+0800
|
21
|
+
# 2.2: Wed Sep 17 10:00:00 [connXXX] ...
|
22
|
+
# 2.4: Wed Sep 17 10:00:00.123 [connXXX] ...
|
23
|
+
# 2.6: 2014-09-17T10:00:43.506+0800 [connXXX] ...
|
24
|
+
# 3.0: 2015-03-18T15:28:44.321+0800 I QUERY [conn5462] ...
|
29
25
|
#unless conf.has_key?("time_format")
|
30
26
|
# #conf["time_format"] = '%a %b %d %H:%M:%S'
|
31
27
|
# #conf["time_format"] = '%a %b %d %H:%M:%S.%L'
|
@@ -41,12 +37,58 @@ module Fluent
|
|
41
37
|
line.chomp! # remove \n
|
42
38
|
time, record = parse_line(line)
|
43
39
|
if time && record
|
44
|
-
record["query"] = get_query_prototype(record["query"])
|
40
|
+
record["query"] = get_query_prototype(record["query"]) if record["query"]
|
45
41
|
record["ms"] = record["ms"].to_i
|
46
42
|
record["ts"] = time
|
43
|
+
|
44
|
+
case record["op"]
|
45
|
+
when "query"
|
46
|
+
when "getmore"
|
47
|
+
res = /ntoskip:(?<ntoskip>\d+)/.match(record["stat"])
|
48
|
+
if res
|
49
|
+
record["ntoskip"] = res["ntoskip"].to_i
|
50
|
+
end
|
51
|
+
res = /nscanned:(?<nscanned>\d+)/.match(record["stat"])
|
52
|
+
if res
|
53
|
+
record["nscanned"] = res["nscanned"].to_i
|
54
|
+
end
|
55
|
+
res = /nreturned:(?<nreturned>\d+)/.match(record["stat"])
|
56
|
+
if res
|
57
|
+
record["nreturned"] = res["nreturned"].to_i
|
58
|
+
end
|
59
|
+
res = /reslen:(?<reslen>\d+)/.match(record["stat"])
|
60
|
+
if res
|
61
|
+
record["reslen"] = res["reslen"].to_i
|
62
|
+
end
|
63
|
+
when "update"
|
64
|
+
res = /nscanned:(?<nscanned>\d+)/.match(record["stat"])
|
65
|
+
if res
|
66
|
+
record["nscanned"] = res["nscanned"].to_i
|
67
|
+
end
|
68
|
+
res = /nMatched:(?<nmatched>\d+)/.match(record["stat"])
|
69
|
+
if res # MongoDB v3.0
|
70
|
+
record["nmatched"] = res["nmatched"].to_i
|
71
|
+
res = /nModified:(?<nmodified>\d+)/.match(record["stat"])
|
72
|
+
if res
|
73
|
+
record["nmodified"] = res["nmodified"].to_i
|
74
|
+
end
|
75
|
+
else # MongoDB v2.4
|
76
|
+
res = /nupdated:(?<nmodified>\d+)/.match(record["stat"])
|
77
|
+
if res
|
78
|
+
record["nmodified"] = res["nmodified"].to_i
|
79
|
+
end
|
80
|
+
end
|
81
|
+
when "remove"
|
82
|
+
res = /ndeleted:(?<ndeleted>\d+)/.match(record["stat"])
|
83
|
+
if res
|
84
|
+
record["ndeleted"] = res["ndeleted"].to_i
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
47
88
|
#if record.has_key?("update")
|
48
89
|
# record["update"] = get_query_prototype(record["update"])
|
49
90
|
#end
|
91
|
+
|
50
92
|
es.add(time, record)
|
51
93
|
end
|
52
94
|
rescue
|
@@ -73,10 +115,11 @@ module Fluent
|
|
73
115
|
ns_array += extract_query_prototype(val, ns)
|
74
116
|
elsif val.class == Array
|
75
117
|
val.each do |item|
|
76
|
-
if item.class == Hash
|
118
|
+
if item.class == Hash # e.g. $eq $gt $gte $lt $lte $ne $in $nin
|
77
119
|
ns_array += extract_query_prototype(item, ns)
|
78
|
-
else
|
79
|
-
ns_array << ns
|
120
|
+
else # e.g. $and $or $nor
|
121
|
+
ns_array << ns
|
122
|
+
break
|
80
123
|
end
|
81
124
|
end
|
82
125
|
else
|
@@ -92,7 +135,7 @@ module Fluent
|
|
92
135
|
prototype = extract_query_prototype(JSON.parse(to_json(query)))
|
93
136
|
return '{ ' + prototype.join(', ') + ' }'
|
94
137
|
rescue
|
95
|
-
$log.
|
138
|
+
$log.warn $!.to_s
|
96
139
|
return query
|
97
140
|
end
|
98
141
|
end
|
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
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.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Caosiyang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description: Fluent plugin for MongoDB slow operation. It's helpful to statistics
|
14
|
+
the slow queries and build indexes
|
14
15
|
email: csy3228@gmail.com
|
15
16
|
executables: []
|
16
17
|
extensions: []
|
@@ -27,18 +28,19 @@ require_paths:
|
|
27
28
|
- lib
|
28
29
|
required_ruby_version: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- - '>='
|
31
|
+
- - ! '>='
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '0'
|
33
34
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
35
|
requirements:
|
35
|
-
- - '>='
|
36
|
+
- - ! '>='
|
36
37
|
- !ruby/object:Gem::Version
|
37
38
|
version: '0'
|
38
39
|
requirements: []
|
39
40
|
rubyforge_project:
|
40
|
-
rubygems_version: 2.
|
41
|
+
rubygems_version: 2.4.5
|
41
42
|
signing_key:
|
42
43
|
specification_version: 4
|
43
|
-
summary:
|
44
|
+
summary: Fluent plugin for MongoDB slow operation. It's helpful to statistics the
|
45
|
+
slow queries and build indexes
|
44
46
|
test_files: []
|