fluent-plugin-mongo-slow-query 0.0.1
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 +7 -0
- data/lib/fluent/plugin/in_mongo_slow_query.rb +69 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8c16e75ba54dd181782178b8aeed4eebae3f3bee
|
4
|
+
data.tar.gz: f5871adf90b4e0afafc945f2d133416d9c0dd0d1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 26ca6c863a0291e93143341515e7296ecaa5902f7bf99cd164e970eaed943ba9240e39f7ff0002800c522307635a17fd315133bbee50a0e9324c6c6911ffe5f9
|
7
|
+
data.tar.gz: a435abc0e37cf99a513d9fec5ec784677e6606dc19428d275d5f667761aac4a02fa8b790ce474a9f61141ac6b87933ed70accc6e3eaececc843c7b073cd4807a
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Fluent
|
4
|
+
class MongoDBSlowQueryInput < TailInput
|
5
|
+
# First, register the plugin. NAME is the name of this plugin
|
6
|
+
# # and identifies the plugin in the configuration file.
|
7
|
+
Plugin.register_input('mongo_slow_query', self)
|
8
|
+
|
9
|
+
# This method is called before starting.
|
10
|
+
# 'conf' is a Hash that includes configuration parameters.
|
11
|
+
# If the configuration is invalid, raise Fluent::ConfigError.
|
12
|
+
def configure(conf)
|
13
|
+
if not conf.has_key?("format")
|
14
|
+
conf["format"] = '/(?<time>[^ ]+ [^ ]+ [^ ]+ [^ ]+) \[\w+\] (?<op>[^ ]+) (?<ns>[^ ]+) (query: (?<query>{.+}) update: (?<update>{.*}))|(query: (?<query>{.+})) .* (?<cost>\d+)ms/'
|
15
|
+
$log.warn "load default format: ", conf["format"]
|
16
|
+
end
|
17
|
+
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
21
|
+
def receive_lines(lines)
|
22
|
+
es = MultiEventStream.new
|
23
|
+
lines.each {|line|
|
24
|
+
begin
|
25
|
+
line.chomp! # remove \n
|
26
|
+
time, record = parse_line(line)
|
27
|
+
if time && record
|
28
|
+
# change query
|
29
|
+
if record.has_key?("query")
|
30
|
+
record["query"] = get_query_prototype(record["query"])
|
31
|
+
es.add(time, record)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
rescue
|
35
|
+
$log.warn line.dump, :error=>$!.to_s
|
36
|
+
$log.debug_backtrace
|
37
|
+
end
|
38
|
+
}
|
39
|
+
|
40
|
+
unless es.empty?
|
41
|
+
begin
|
42
|
+
Engine.emit_stream(@tag, es)
|
43
|
+
rescue
|
44
|
+
#ignore errors. Engine shows logs and backtraces.
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# exrtact query prototype recursively
|
50
|
+
def extract_query_prototype(query_json_obj, parent='')
|
51
|
+
ns_array = []
|
52
|
+
query_json_obj.each do |key, val|
|
53
|
+
ns = parent.empty? ? key : (parent + '.' + key)
|
54
|
+
if val.class == Hash
|
55
|
+
ns_array += extract_query_prototype(val, ns)
|
56
|
+
else
|
57
|
+
ns_array << ns
|
58
|
+
end
|
59
|
+
end
|
60
|
+
return ns_array
|
61
|
+
end
|
62
|
+
|
63
|
+
# get query prototype
|
64
|
+
def get_query_prototype(query)
|
65
|
+
prototype = extract_query_prototype(JSON.parse(eval(query).to_json))
|
66
|
+
return '{ ' + prototype.join(', ') + ' }'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-mongo-slow-query
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- caosiyang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-26 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: fluent plugin for mongo slow query
|
14
|
+
email: csy3228@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/fluent/plugin/in_mongo_slow_query.rb
|
20
|
+
homepage: https://github.com/caosiyang/fluent-plugin-mongo-slow-query
|
21
|
+
licenses:
|
22
|
+
- ''
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.3.0
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: fluent plugin for mongo slow query
|
44
|
+
test_files: []
|