fluent-plugin-storage-redis 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 +10 -0
- data/.travis.yml +12 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +56 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/fluent-plugin-storage-redis.gemspec +37 -0
- data/lib/fluent/plugin/storage_redis.rb +96 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9fb24c52cf1a0511f8edbf5df0c2fcc4494f1a94
|
4
|
+
data.tar.gz: e6aa5a7a15ec6dfc3ab692a4825d38544c4141b6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2946ec9dcd8734ef7629ab9131ac498e2e7959317da76b75b34895ef67aafa4fbdc1d0a1a7be5873e75d3d5884aa6fdc42e587a7d8749104b4b5c4b49d38e86b
|
7
|
+
data.tar.gz: b1a7bf3bb01a9406fe4a387e3e74af02dede864c61765752736567d7f805078bd7494aba5e59792f8f917bbd652acf63045d6b7b9fc20c47428620b515b89a1d
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Hiroshi Hatake
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Redis storage plugin for Fluent
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/cosmo0920/fluent-plugin-storage-redis.svg?branch=master)](https://travis-ci.org/cosmo0920/fluent-plugin-storage-redis)
|
4
|
+
|
5
|
+
fluent-plugin-storage-redis is a fluent plugin to store plugin state into redis.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'fluent-plugin-storage-redis'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install fluent-plugin-storage-redis
|
22
|
+
|
23
|
+
Then fluent automatically loads the plugin installed.
|
24
|
+
|
25
|
+
## Configuration
|
26
|
+
|
27
|
+
```aconf
|
28
|
+
<store>
|
29
|
+
@type redis
|
30
|
+
|
31
|
+
path my_key # or conf.arg will be used as redis key
|
32
|
+
host localhost # localhost is default
|
33
|
+
port 6379 # 6379 is default
|
34
|
+
db_number 0 # 0 is default
|
35
|
+
# If requirepass is set, please specify this.
|
36
|
+
# password hogefuga
|
37
|
+
</match>
|
38
|
+
```
|
39
|
+
|
40
|
+
## Development
|
41
|
+
|
42
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
43
|
+
|
44
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/cosmo0920/fluent-plugin-storage-redis.
|
49
|
+
|
50
|
+
## Copyright
|
51
|
+
|
52
|
+
Copyright (c) 2017- Hiroshi Hatake
|
53
|
+
|
54
|
+
## License
|
55
|
+
|
56
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "fluent/plugin/storage/redis"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,37 @@
|
|
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-storage-redis"
|
7
|
+
spec.version = "0.0.1"
|
8
|
+
spec.authors = ["Hiroshi Hatake"]
|
9
|
+
spec.email = ["cosmo0920.oucc@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{Fluentd storage plugin for Redis}
|
12
|
+
spec.description = %q{Fluentd storage plugin for Redis}
|
13
|
+
spec.homepage = "https://github.com/cosmo0920/fluent-plugin-storage-redis"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
22
|
+
"public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
33
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
34
|
+
spec.add_development_dependency "test-unit", "~> 3.2.0"
|
35
|
+
spec.add_dependency "fluentd", [">= 0.14.12", "< 2"]
|
36
|
+
spec.add_dependency "redis", "~> 3.3.0"
|
37
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'redis'
|
2
|
+
require 'fluent/plugin/storage'
|
3
|
+
|
4
|
+
module Fluent
|
5
|
+
module Plugin
|
6
|
+
class RedisStorage < Storage
|
7
|
+
Fluent::Plugin.register_storage('redis', self)
|
8
|
+
|
9
|
+
config_param :path, :string, default: nil
|
10
|
+
config_param :host, :string, default: 'localhost'
|
11
|
+
config_param :port, :integer, default: 6379
|
12
|
+
config_param :db_number, :integer, default: 0
|
13
|
+
config_param :password, :string, default: nil, secret: true
|
14
|
+
|
15
|
+
attr_reader :store # for test
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
super
|
19
|
+
|
20
|
+
@store = {}
|
21
|
+
end
|
22
|
+
|
23
|
+
def configure(conf)
|
24
|
+
super
|
25
|
+
|
26
|
+
unless @path
|
27
|
+
if conf && !conf.arg.empty?
|
28
|
+
@path = conf.arg
|
29
|
+
else
|
30
|
+
raise Fluent::ConfigError, "path or conf.arg for <storage> is required."
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
options = {
|
35
|
+
host: @host,
|
36
|
+
port: @port,
|
37
|
+
thread_safe: true,
|
38
|
+
db: @db_number
|
39
|
+
}
|
40
|
+
options[:password] = @password if @password
|
41
|
+
|
42
|
+
@redis = Redis.new(options)
|
43
|
+
end
|
44
|
+
|
45
|
+
def multi_workers_ready?
|
46
|
+
true
|
47
|
+
end
|
48
|
+
|
49
|
+
def load
|
50
|
+
begin
|
51
|
+
json_string = @redis.get(@path)
|
52
|
+
json = Yajl::Parser.parse(json_string)
|
53
|
+
unless json.is_a?(Hash)
|
54
|
+
log.error "broken content for plugin storage (Hash required: ignored)", type: json.class
|
55
|
+
log.debug "broken content", content: json_string
|
56
|
+
return
|
57
|
+
end
|
58
|
+
@store = json
|
59
|
+
rescue => e
|
60
|
+
log.error "failed to load data for plugin storage from redis", path: @path, error: e
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def save
|
65
|
+
begin
|
66
|
+
json_string = Yajl::Encoder.encode(@store)
|
67
|
+
@redis.pipelined {
|
68
|
+
@redis.set(@path, json_string)
|
69
|
+
}
|
70
|
+
rescue => e
|
71
|
+
log.error "failed to save data for plugin storage to redis", path: @path, error: e
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def get(key)
|
76
|
+
@store[key.to_s]
|
77
|
+
end
|
78
|
+
|
79
|
+
def fetch(key, defval)
|
80
|
+
@store.fetch(key.to_s, defval)
|
81
|
+
end
|
82
|
+
|
83
|
+
def put(key, value)
|
84
|
+
@store[key.to_s] = value
|
85
|
+
end
|
86
|
+
|
87
|
+
def delete(key)
|
88
|
+
@store.delete(key.to_s)
|
89
|
+
end
|
90
|
+
|
91
|
+
def update(key, &block)
|
92
|
+
@store[key.to_s] = block.call(@store[key.to_s])
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-storage-redis
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hiroshi Hatake
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '12.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '12.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: test-unit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.2.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.2.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: fluentd
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.14.12
|
62
|
+
- - "<"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '2'
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 0.14.12
|
72
|
+
- - "<"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '2'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: redis
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 3.3.0
|
82
|
+
type: :runtime
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 3.3.0
|
89
|
+
description: Fluentd storage plugin for Redis
|
90
|
+
email:
|
91
|
+
- cosmo0920.oucc@gmail.com
|
92
|
+
executables: []
|
93
|
+
extensions: []
|
94
|
+
extra_rdoc_files: []
|
95
|
+
files:
|
96
|
+
- ".gitignore"
|
97
|
+
- ".travis.yml"
|
98
|
+
- Gemfile
|
99
|
+
- LICENSE.txt
|
100
|
+
- README.md
|
101
|
+
- Rakefile
|
102
|
+
- bin/console
|
103
|
+
- bin/setup
|
104
|
+
- fluent-plugin-storage-redis.gemspec
|
105
|
+
- lib/fluent/plugin/storage_redis.rb
|
106
|
+
homepage: https://github.com/cosmo0920/fluent-plugin-storage-redis
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata:
|
110
|
+
allowed_push_host: https://rubygems.org
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 2.6.8
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: Fluentd storage plugin for Redis
|
131
|
+
test_files: []
|