fluent-plugin-redis-slowlog 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +23 -0
- data/Rakefile +11 -0
- data/fluent-plugin-redis-slowlog.gemspec +23 -0
- data/lib/fluent/plugin/in_redis_slowlog.rb +64 -0
- data/test/helper.rb +30 -0
- data/test/plugin/test_in_redis_slowlog.rb +24 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8078c5a5ddb8feb59f7d93bd084c16c85b12f494
|
4
|
+
data.tar.gz: ef88a828fde94f123797caadfb1aacb961e2b65a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f934bc93e703cec553f034d18394df9a43ca9d75d9f7af02f8c1a7c5c080e1caaa985d354d36116d8adc9ec86b15b01c10917968340e1e27d83c59ea895aa0e8
|
7
|
+
data.tar.gz: ec064f6ea040fb399aefeb2890a9384849283e37d4d20f32312995a7159a9f49707836453546f3402c48b5cd496ddf1a97b259a819c63ab745db19629f85f20d
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 shingo suzuki
|
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,23 @@
|
|
1
|
+
# fluent-plugin-redis-slowlog [![Build Status](https://travis-ci.org/mominosin/fluent-plugin-redis-slowlog.svg?branch=master)](https://travis-ci.org/mominosin/fluent-plugin-redis-slowlog)
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
$ gem install fluent-plugin-redis-slowlog
|
6
|
+
|
7
|
+
## Configuration
|
8
|
+
```config
|
9
|
+
<source>
|
10
|
+
type redis_slowlog
|
11
|
+
host [Redis Hostname]
|
12
|
+
port [Redis Port (default: 63790)]
|
13
|
+
logsize [Redis Command(SLOWLOG get logsise) (default:128)]
|
14
|
+
interval [Redis Command(SLOWLOG get logsize) interval (default:10)]
|
15
|
+
tag redis.slowlog
|
16
|
+
</source>
|
17
|
+
```
|
18
|
+
|
19
|
+
### output
|
20
|
+
```
|
21
|
+
2014-06-08 05:33:51 +0900 redis.slowlog: {"id":176,"timestamp":1402173275,"exec_time":9,"command":["set","hoge","aga"]}
|
22
|
+
2014-06-08 05:33:51 +0900 redis.slowlog: {"id":175,"timestamp":1402173273,"exec_time":137,"command":["slowlog","get","128"]}
|
23
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "fluent-plugin-redis-slowlog"
|
7
|
+
spec.version = "0.0.1"
|
8
|
+
spec.authors = ["shingo suzuki"]
|
9
|
+
spec.email = ["s_suzuking@icloud.com"]
|
10
|
+
spec.description = "Redis slowlog input plugin for Fluent event collector"
|
11
|
+
spec.summary = spec.description
|
12
|
+
spec.homepage = "https://github.com/mominosin/fluent-plugin-redis-slowlog"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "rake"
|
21
|
+
spec.add_runtime_dependency "fluentd"
|
22
|
+
spec.add_runtime_dependency "redis"
|
23
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
class Fluent::Redis_SlowlogInput < Fluent::Input
|
2
|
+
Fluent::Plugin.register_input('redis_slowlog', self)
|
3
|
+
|
4
|
+
config_param :tag, :string
|
5
|
+
config_param :host, :string, :default => nil
|
6
|
+
config_param :port, :integer, :default => 6379
|
7
|
+
config_param :logsize, :integer, :default => 128
|
8
|
+
config_param :interval, :integer, :default => 10
|
9
|
+
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
super
|
13
|
+
require 'redis'
|
14
|
+
end
|
15
|
+
|
16
|
+
def configure(conf)
|
17
|
+
super
|
18
|
+
@redis = Redis.new(
|
19
|
+
:host => @host,
|
20
|
+
:port => @port
|
21
|
+
)
|
22
|
+
pong = @redis.ping
|
23
|
+
begin
|
24
|
+
unless pong == 'PONG'
|
25
|
+
raise "fluent-plugin-redis-slowlog: cannot connect redis"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
@log_id = 0
|
29
|
+
@get_interval = @interval
|
30
|
+
end
|
31
|
+
|
32
|
+
def start
|
33
|
+
super
|
34
|
+
@watcher = Thread.new(&method(:watch))
|
35
|
+
end
|
36
|
+
|
37
|
+
def shutdown
|
38
|
+
super
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def watch
|
43
|
+
while true
|
44
|
+
sleep @get_interval
|
45
|
+
@log_id = output( @log_id )
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def output( last_id = 0)
|
50
|
+
slow_logs = []
|
51
|
+
slow_logs = @redis.slowlog('get', logsize)
|
52
|
+
|
53
|
+
log_id = slow_logs[0][0]
|
54
|
+
slow_logs.each do |log|
|
55
|
+
unless log[0] > last_id
|
56
|
+
break
|
57
|
+
end
|
58
|
+
log_hash = { id: log[0], timestamp: log[1], exec_time: log[2], command: log[3] }
|
59
|
+
Fluent::Engine.emit(tag, Time.now.to_i, log_hash)
|
60
|
+
end
|
61
|
+
return log_id
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,30 @@
|
|
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_redis_slowlog'
|
26
|
+
|
27
|
+
class Test::Unit::TestCase
|
28
|
+
end
|
29
|
+
|
30
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Redis_SlowlogInputTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
Fluent::Test.setup
|
7
|
+
end
|
8
|
+
|
9
|
+
CONFIG = %[
|
10
|
+
tag redis-slowlog
|
11
|
+
host localhost
|
12
|
+
port 6379
|
13
|
+
logsize 128
|
14
|
+
interval 10
|
15
|
+
]
|
16
|
+
|
17
|
+
def create_driver(conf = CONFIG)
|
18
|
+
Fluent::Test::InputTestDriver.new(Fluent::Redis_SlowlogInput).configure(conf)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_configure
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-redis-slowlog
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- shingo suzuki
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-07 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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: redis
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Redis slowlog input plugin for Fluent event collector
|
56
|
+
email:
|
57
|
+
- s_suzuking@icloud.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .travis.yml
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- fluent-plugin-redis-slowlog.gemspec
|
69
|
+
- lib/fluent/plugin/in_redis_slowlog.rb
|
70
|
+
- test/helper.rb
|
71
|
+
- test/plugin/test_in_redis_slowlog.rb
|
72
|
+
homepage: https://github.com/mominosin/fluent-plugin-redis-slowlog
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.2.2
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Redis slowlog input plugin for Fluent event collector
|
96
|
+
test_files:
|
97
|
+
- test/helper.rb
|
98
|
+
- test/plugin/test_in_redis_slowlog.rb
|