fluent-plugin-werkzeug-profiler 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/.gitignore +46 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +59 -0
- data/Rakefile +12 -0
- data/fluent-plugin-werkzeug-profiler.gemspec +20 -0
- data/lib/fluent/plugin/in_werkzeug_profiler.rb +94 -0
- data/test/helper.rb +29 -0
- data/test/plugin/test_in_werkzeug_profiler.rb +68 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 739f2096bb9c486f62f7a66100ceedc3b73ef5ab
|
4
|
+
data.tar.gz: 3819d28c2bfdf620583bbdbecc5ec20c720fca84
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 98abcf85d13e7656fad288229e04e5c619eedc9105da91995df78ce00fc1386a4f3c1b143417ee0ca1fac895eee7e6ab95d9864a2cfeaa9ad0308a5393ad3efa
|
7
|
+
data.tar.gz: dbf2f1a901ff19f750475c9b6873e915773ca8ead4d59a86cff99e8c6917d10bb4f9f2b5649681963a94c69d9cfe082cd1069e509f9ea20595268ed00996dc57
|
data/.gitignore
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Created by http://gitignore.io
|
2
|
+
|
3
|
+
### OSX ###
|
4
|
+
.DS_Store
|
5
|
+
.AppleDouble
|
6
|
+
.LSOverride
|
7
|
+
Icon
|
8
|
+
|
9
|
+
# Thumbnails
|
10
|
+
._*
|
11
|
+
|
12
|
+
# Files that might appear on external disk
|
13
|
+
.Spotlight-V100
|
14
|
+
.Trashes
|
15
|
+
|
16
|
+
### vim ###
|
17
|
+
.*.s[a-w][a-z]
|
18
|
+
*.un~
|
19
|
+
Session.vim
|
20
|
+
.netrwhist
|
21
|
+
*~
|
22
|
+
|
23
|
+
### Ruby ###
|
24
|
+
*.gem
|
25
|
+
*.rbc
|
26
|
+
.bundle
|
27
|
+
.config
|
28
|
+
.yardoc
|
29
|
+
Gemfile.lock
|
30
|
+
InstalledFiles
|
31
|
+
_yardoc
|
32
|
+
coverage
|
33
|
+
doc/
|
34
|
+
lib/bundler/man
|
35
|
+
pkg
|
36
|
+
rdoc
|
37
|
+
spec/reports
|
38
|
+
test/tmp
|
39
|
+
test/version_tmp
|
40
|
+
tmp
|
41
|
+
|
42
|
+
# YARD artifacts
|
43
|
+
.yardoc
|
44
|
+
_yardoc
|
45
|
+
doc/
|
46
|
+
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Kenta MORI
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# fluent-plugin-werkzeug-profiler
|
2
|
+
|
3
|
+
## Component
|
4
|
+
|
5
|
+
### WerkzeugProfilerInput
|
6
|
+
|
7
|
+
Fluent input plugin for Werkzeug WSGI application profiler statistics.
|
8
|
+
|
9
|
+
For example, Werkzeug profiler output following log.
|
10
|
+
```
|
11
|
+
----------------------------------------
|
12
|
+
PATH: '/'
|
13
|
+
15724 function calls (14741 primitive calls) in 0.418 seconds
|
14
|
+
|
15
|
+
Ordered by: internal time, call count
|
16
|
+
List reduced from 490 to 30 due to restriction <30>
|
17
|
+
|
18
|
+
ncalls tottime percall cumtime percall filename:lineno(function)
|
19
|
+
2 0.226 0.113 0.226 0.113 {method 'query' of '_mysql.connection' objects}
|
20
|
+
1 0.000 0.000 0.026 0.026 build/bdist.linux-x86_64/egg/MySQLdb/__init__.py:78(Connect)
|
21
|
+
99/31 0.000 0.000 0.000 0.000 /usr/lib/python2.7/sre_parse.py:141(getwidth)
|
22
|
+
|
23
|
+
----------------------------------------
|
24
|
+
```
|
25
|
+
Results are as follows.
|
26
|
+
```
|
27
|
+
{ "uri"=>"/", "tot_ncalls"=>"2", "prim_ncalls"=>"2", "tottime"=>"0.226",
|
28
|
+
"tot_percall"=>"0.113", "cumtime"=>"0.226", "cum_percall"=>"0.113",
|
29
|
+
"filename:lineno(function)"=>"{method 'query' of '_mysql.connection' objects}" },
|
30
|
+
{ "uri"=>"/", "tot_ncalls"=>"1", "prim_ncalls"=>"1", "tottime"=>"0.000",
|
31
|
+
"tot_percall"=>"0.000", "cumtime"=>"0.026", "cum_percall"=>"0.026",
|
32
|
+
"filename:lineno(function)"=>"build/bdist.linux- x86_64/egg/MySQLdb/__init__.py:78(Connect)" },
|
33
|
+
{ "uri"=>"/", "tot_ncalls"=>"99", "prim_ncalls"=>"31", "tottime"=>"0.000",
|
34
|
+
"tot_percall"=>"0.000", "cumtime"=>"0.000", "cum_percall"=>"0.000",
|
35
|
+
["filename:lineno(function)"=>"/usr/lib/python2.7/sre_parse.py:141(getwidth)" }
|
36
|
+
```
|
37
|
+
|
38
|
+
## Installation
|
39
|
+
|
40
|
+
```
|
41
|
+
$ gem install fluent-plugin-werkzeug-profiler
|
42
|
+
```
|
43
|
+
|
44
|
+
## Configuration
|
45
|
+
|
46
|
+
### WerkzeugProfilerInput
|
47
|
+
|
48
|
+
```
|
49
|
+
<source>
|
50
|
+
type werkzeug
|
51
|
+
path path/to/werkzeug.log
|
52
|
+
tag werkzeug.webserver
|
53
|
+
time_format %d-%b-%Y:%H:%M:%S
|
54
|
+
</source>
|
55
|
+
```
|
56
|
+
|
57
|
+
## License
|
58
|
+
|
59
|
+
This software is released under the MIT License, see LICENSE.txt.
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = "fluent-plugin-werkzeug-profiler"
|
5
|
+
gem.version = "0.0.1"
|
6
|
+
gem.authors = ["Kenta MORI"]
|
7
|
+
gem.email = ["zoncoen@gmail.com"]
|
8
|
+
gem.description = %q{Fluent input plugin for Werkzeug WSGI application profiler statistics.}
|
9
|
+
gem.summary = %q{Fluent input plugin for Werkzeug WSGI application profiler statistics.}
|
10
|
+
gem.homepage = "https://github.com/zoncoen/fluent-plugin-werkzeug-profiler.git"
|
11
|
+
gem.license = "MIT"
|
12
|
+
|
13
|
+
gem.files = `git ls-files`.split($/)
|
14
|
+
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
15
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
16
|
+
gem.require_paths = ["lib"]
|
17
|
+
|
18
|
+
gem.add_development_dependency "rake"
|
19
|
+
gem.add_runtime_dependency "fluentd"
|
20
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module Fluent
|
2
|
+
|
3
|
+
class WerkzeugProfilerInput < TailInput
|
4
|
+
Plugin.register_input('werkzeug', self)
|
5
|
+
|
6
|
+
# get time format from config
|
7
|
+
config_param :time_format, :string, :default => '%d/%b/%Y:%H:%M:%S %z'
|
8
|
+
|
9
|
+
# override
|
10
|
+
def configure_parser(conf)
|
11
|
+
@parser = WerkzeugProfilerParser.new(@time_format)
|
12
|
+
end
|
13
|
+
|
14
|
+
# override
|
15
|
+
def receive_lines(lines)
|
16
|
+
es = MultiEventStream.new
|
17
|
+
|
18
|
+
for line in @parser.divide(lines) do
|
19
|
+
begin
|
20
|
+
time, record = parse_line(line)
|
21
|
+
if time && record
|
22
|
+
es.add(time, record)
|
23
|
+
end
|
24
|
+
rescue
|
25
|
+
$log.warn line.dump, :error=>$!.to_s
|
26
|
+
$log.debug_backtrace
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
unless es.empty?
|
31
|
+
Engine.emit_stream(@tag, es)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class WerkzeugProfilerParser
|
36
|
+
def initialize(time_format)
|
37
|
+
@time_format = time_format
|
38
|
+
@keys = ['uri', 'tot_ncalls', 'prim_ncalls', 'tottime', 'tot_percall', 'cumtime', 'cum_percall', 'filename:lineno(function)']
|
39
|
+
@record_size = @keys.length - 2
|
40
|
+
@path = 'path'
|
41
|
+
@time = 'time'
|
42
|
+
end
|
43
|
+
|
44
|
+
def parse(values)
|
45
|
+
time = values.shift
|
46
|
+
array = [@keys,values].transpose.flatten
|
47
|
+
record = Hash[*array]
|
48
|
+
return time, record
|
49
|
+
end
|
50
|
+
|
51
|
+
def divide(lines)
|
52
|
+
records = []
|
53
|
+
# remove empty lines
|
54
|
+
lines = lines.join('').gsub(/\n\n/, "\n").split("\n")
|
55
|
+
|
56
|
+
for line in lines do
|
57
|
+
if line.start_with?('-')
|
58
|
+
@path = nil
|
59
|
+
next
|
60
|
+
end
|
61
|
+
|
62
|
+
if line.start_with?('PATH:')
|
63
|
+
path = line.split(nil)[1]
|
64
|
+
@path = path[1..path.length-2]
|
65
|
+
@time = Time.now.strftime(@time_format)
|
66
|
+
next
|
67
|
+
end
|
68
|
+
|
69
|
+
if line.strip.split(nil)[1] == 'function' || line.strip.start_with?('ncalls', 'Ordered', 'List')
|
70
|
+
next
|
71
|
+
elsif @path != nil
|
72
|
+
values = line.split(nil)
|
73
|
+
# divide ncalls
|
74
|
+
ncalls = values[0].split('/')
|
75
|
+
values[0] = ncalls[0]
|
76
|
+
values[1,0] = ncalls[ncalls.length-1]
|
77
|
+
if values.length > @record_size + 1
|
78
|
+
values[@record_size] = values[@record_size..values.length-1].join(' ')
|
79
|
+
end
|
80
|
+
record = values[0..@record_size]
|
81
|
+
record.unshift(@path)
|
82
|
+
record.unshift(@time)
|
83
|
+
records << record
|
84
|
+
next
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# return records as array
|
89
|
+
records
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
13
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
14
|
+
require 'fluent/test'
|
15
|
+
unless ENV.has_key?('VERBOSE')
|
16
|
+
nulllogger = Object.new
|
17
|
+
nulllogger.instance_eval {|obj|
|
18
|
+
def method_missing(method, *args)
|
19
|
+
# pass
|
20
|
+
end
|
21
|
+
}
|
22
|
+
$log = nulllogger
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'fluent/plugin/in_tail'
|
26
|
+
require 'fluent/plugin/in_werkzeug_profiler'
|
27
|
+
|
28
|
+
class Test::Unit::TestCase
|
29
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
class WerkzeugProfilerInputTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
Fluent::Test.setup
|
7
|
+
FileUtils.rm_rf(TMP_DIR)
|
8
|
+
FileUtils.mkdir_p(TMP_DIR)
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
FileUtils.rm_rf(TMP_DIR)
|
13
|
+
end
|
14
|
+
|
15
|
+
TMP_DIR = File.dirname(__FILE__) + "/../tmp"
|
16
|
+
|
17
|
+
CONFIG = %[
|
18
|
+
path #{TMP_DIR}/werkzeug-profiler-test.txt
|
19
|
+
time_format %d-%b-%Y:%H:%M:%S
|
20
|
+
tag test
|
21
|
+
]
|
22
|
+
|
23
|
+
def create_driver(conf = CONFIG)
|
24
|
+
Fluent::Test::InputTestDriver.new(Fluent::WerkzeugProfilerInput).configure(conf)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_configure
|
28
|
+
d = create_driver
|
29
|
+
assert_equal ["#{TMP_DIR}/werkzeug-profiler-test.txt"], d.instance.paths
|
30
|
+
assert_equal "%d-%b-%Y:%H:%M:%S", d.instance.time_format
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_emit
|
34
|
+
File.open("#{TMP_DIR}/werkzeug-profiler-test.txt", "w") {|f|
|
35
|
+
f.puts "old logs."
|
36
|
+
}
|
37
|
+
|
38
|
+
d = create_driver
|
39
|
+
|
40
|
+
d.run do
|
41
|
+
sleep 1
|
42
|
+
|
43
|
+
File.open("#{TMP_DIR}/werkzeug-profiler-test.txt", "a") {|f|
|
44
|
+
f.puts "--------------------------------------------------------------------------------"
|
45
|
+
f.puts "PATH: '/'"
|
46
|
+
f.puts " 15724 function calls (14741 primitive calls) in 0.418 seconds"
|
47
|
+
f.puts ""
|
48
|
+
f.puts " Ordered by: internal time, call count"
|
49
|
+
f.puts " List reduced from 490 to 30 due to restriction <30>"
|
50
|
+
f.puts ""
|
51
|
+
f.puts " ncalls tottime percall cumtime percall filename:lineno(function)"
|
52
|
+
f.puts " 2 0.226 0.113 0.226 0.113 {method 'query' of '_mysql.connection' objects}"
|
53
|
+
f.puts " 1 0.000 0.000 0.026 0.026 build/bdist.linux-x86_64/egg/MySQLdb/__init__.py:78(Connect)"
|
54
|
+
f.puts " 99/31 0.000 0.000 0.000 0.000 /usr/lib/python2.7/sre_parse.py:141(getwidth)"
|
55
|
+
f.puts ""
|
56
|
+
f.puts "--------------------------------------------------------------------------------"
|
57
|
+
f.puts ""
|
58
|
+
}
|
59
|
+
sleep 1
|
60
|
+
end
|
61
|
+
|
62
|
+
emits = d.emits
|
63
|
+
assert_equal(true, emits.length > 0)
|
64
|
+
assert_equal({"uri"=>"/", "tot_ncalls"=>"2", "prim_ncalls"=>"2", "tottime"=>"0.226", "tot_percall"=>"0.113", "cumtime"=>"0.226", "cum_percall"=>"0.113", "filename:lineno(function)"=>"{method 'query' of '_mysql.connection' objects}"}, emits[0][2])
|
65
|
+
assert_equal({"uri"=>"/", "tot_ncalls"=>"1", "prim_ncalls"=>"1", "tottime"=>"0.000", "tot_percall"=>"0.000", "cumtime"=>"0.026", "cum_percall"=>"0.026", "filename:lineno(function)"=>"build/bdist.linux-x86_64/egg/MySQLdb/__init__.py:78(Connect)"}, emits[1][2])
|
66
|
+
assert_equal({"uri"=>"/", "tot_ncalls"=>"99", "prim_ncalls"=>"31", "tottime"=>"0.000", "tot_percall"=>"0.000", "cumtime"=>"0.000", "cum_percall"=>"0.000", "filename:lineno(function)"=>"/usr/lib/python2.7/sre_parse.py:141(getwidth)"}, emits[2][2])
|
67
|
+
end
|
68
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-werkzeug-profiler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kenta MORI
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: fluentd
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Fluent input plugin for Werkzeug WSGI application profiler statistics.
|
42
|
+
email:
|
43
|
+
- zoncoen@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- fluent-plugin-werkzeug-profiler.gemspec
|
54
|
+
- lib/fluent/plugin/in_werkzeug_profiler.rb
|
55
|
+
- test/helper.rb
|
56
|
+
- test/plugin/test_in_werkzeug_profiler.rb
|
57
|
+
homepage: https://github.com/zoncoen/fluent-plugin-werkzeug-profiler.git
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.1.0
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Fluent input plugin for Werkzeug WSGI application profiler statistics.
|
81
|
+
test_files:
|
82
|
+
- test/helper.rb
|
83
|
+
- test/plugin/test_in_werkzeug_profiler.rb
|