fluent-plugin-mongo-slow-query 0.0.4 → 0.0.5

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
  SHA1:
3
- metadata.gz: 073b844f677ea653c53e0ab6dba3acd74bed13b3
4
- data.tar.gz: a3772a54e28b746268facbef28785ee247fb0339
3
+ metadata.gz: 284e26c6dc167bed1678ea14f4efb320be3148e5
4
+ data.tar.gz: a50274330aa6b8fe11eb052d4fa2414cf095ba1d
5
5
  SHA512:
6
- metadata.gz: 679b03443566dee67ac0d7b211071bcfba1b10a36369b9031bc906eb201d09de796a71b634ef7a8d541379a6562aad4635bcd3900f127320d73d73810e0f61a6
7
- data.tar.gz: 50b3432e8542aa08a2cd5fda521a9def447a79f62672591d3fd98926546db135e56b2c9ec3ba7e9afa597bb45bbfdec270873dfcb0b073fd3c794a3af9c0bca5
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
- #conf["format"] = '/(?<time>[^ ]+ [^ ]+ [^ ]+ [^ ]+) \[\w+\] (?<op>[^ ]+) (?<ns>[^ ]+) ((query: (?<query>{.+}) update: (?<update>{.*}))|(query: (?<query>{.+}))) .* (?<ms>\d+)ms/'
15
- conf["format"] = '/(?<time>.*) \[\w+\] (?<op>[^ ]+) (?<ns>[^ ]+) ((query: (?<query>{.+}) update: {.*})|(query: (?<query>{.+}))) .* (?<ms>\d+)ms/'
16
- $log.warn "load default format: ", conf["format"]
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
- unless conf.has_key?("time_format")
20
- conf["time_format"] = '%a %b %d %H:%M:%S.%L'
21
- $log.warn "load default time_format: ", conf["time_format"]
22
- end
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
- # get prototype
34
- if record.has_key?("query")
35
- record["query"] = get_query_prototype(record["query"])
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.gsub(/( [^ ]+?: )/) {|fieldname| fieldname_format(fieldname)}
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
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-07-31 00:00:00.000000000 Z
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