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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1d1c2fa9da92102d0517324f87482aa9f552d30
4
- data.tar.gz: a6fbdb01ba0d0fa8f597f32fab8038e0d8388a2a
3
+ metadata.gz: 073b844f677ea653c53e0ab6dba3acd74bed13b3
4
+ data.tar.gz: a3772a54e28b746268facbef28785ee247fb0339
5
5
  SHA512:
6
- metadata.gz: 33359191371e974322482d504d22949834197b89ec128d0e60ba58b152a7210ea32db47d25c9eb6b35cc515b6eea2b3854d5847bd409f8cb1702843a17df9e05
7
- data.tar.gz: be387dc660ed8b9241294df6474386ab1ffce4de81ca73ec0f12d409f5c4137736f5f58066944a222aff5c205879462546482542096f8a4f0a865856582272c2
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>[^ ]+ [^ ]+ [^ ]+ [^ ]+) \[\w+\] (?<op>[^ ]+) (?<ns>[^ ]+) ((query: (?<query>{.+}) update: {.*})|(query: (?<query>{.+}))) .* (?<ms>\d+)ms/'
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(eval(query).to_json))
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.3
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-01 00:00:00.000000000 Z
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