fluent-plugin-mongo-slow-query 0.0.3 → 0.0.4
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 +22 -2
- 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: 073b844f677ea653c53e0ab6dba3acd74bed13b3
|
4
|
+
data.tar.gz: a3772a54e28b746268facbef28785ee247fb0339
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 679b03443566dee67ac0d7b211071bcfba1b10a36369b9031bc906eb201d09de796a71b634ef7a8d541379a6562aad4635bcd3900f127320d73d73810e0f61a6
|
7
|
+
data.tar.gz: 50b3432e8542aa08a2cd5fda521a9def447a79f62672591d3fd98926546db135e56b2c9ec3ba7e9afa597bb45bbfdec270873dfcb0b073fd3c794a3af9c0bca5
|
@@ -12,7 +12,7 @@ module Fluent
|
|
12
12
|
def configure(conf)
|
13
13
|
unless conf.has_key?("format")
|
14
14
|
#conf["format"] = '/(?<time>[^ ]+ [^ ]+ [^ ]+ [^ ]+) \[\w+\] (?<op>[^ ]+) (?<ns>[^ ]+) ((query: (?<query>{.+}) update: (?<update>{.*}))|(query: (?<query>{.+}))) .* (?<ms>\d+)ms/'
|
15
|
-
conf["format"] = '/(?<time
|
15
|
+
conf["format"] = '/(?<time>.*) \[\w+\] (?<op>[^ ]+) (?<ns>[^ ]+) ((query: (?<query>{.+}) update: {.*})|(query: (?<query>{.+}))) .* (?<ms>\d+)ms/'
|
16
16
|
$log.warn "load default format: ", conf["format"]
|
17
17
|
end
|
18
18
|
|
@@ -61,6 +61,14 @@ module Fluent
|
|
61
61
|
ns = parent.empty? ? key : (parent + '.' + key)
|
62
62
|
if val.class == Hash
|
63
63
|
ns_array += extract_query_prototype(val, ns)
|
64
|
+
elsif val.class == Array
|
65
|
+
val.each do |item|
|
66
|
+
if item.class == Hash
|
67
|
+
ns_array += extract_query_prototype(item, ns)
|
68
|
+
else
|
69
|
+
ns_array << ns + '.' + item
|
70
|
+
end
|
71
|
+
end
|
64
72
|
else
|
65
73
|
ns_array << ns
|
66
74
|
end
|
@@ -71,12 +79,24 @@ module Fluent
|
|
71
79
|
# get query prototype
|
72
80
|
def get_query_prototype(query)
|
73
81
|
begin
|
74
|
-
prototype = extract_query_prototype(JSON.parse(
|
82
|
+
prototype = extract_query_prototype(JSON.parse(to_json(query)))
|
75
83
|
return '{ ' + prototype.join(', ') + ' }'
|
76
84
|
rescue
|
77
85
|
$log.error $!.to_s
|
78
86
|
return query
|
79
87
|
end
|
80
88
|
end
|
89
|
+
|
90
|
+
# convert query to JSON
|
91
|
+
def to_json(query)
|
92
|
+
res = query.gsub(/( [^ ]+?: )/) {|fieldname| fieldname_format(fieldname)}
|
93
|
+
return res
|
94
|
+
end
|
95
|
+
|
96
|
+
# format fieldname in query
|
97
|
+
# e.g.: { id: 1 } => { "id": 1 }
|
98
|
+
def fieldname_format(fieldname)
|
99
|
+
return ' "%s": ' % fieldname.strip.chomp(':')
|
100
|
+
end
|
81
101
|
end
|
82
102
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- caosiyang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: fluent plugin for mongo slow query
|
14
14
|
email: csy3228@gmail.com
|