fluent-plugin-file-sprintf 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 +6 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +123 -0
- data/Rakefile +17 -0
- data/fluent-plugin-file-sprintf.gemspec +23 -0
- data/lib/fluent/plugin/out_file_sprintf.rb +82 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b5a4f17b7e16b09210c8e077f49a1a0e3b2b2944
|
4
|
+
data.tar.gz: 8722818ad5766d16dd4cb05fa9446e916fa28d57
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9873101ad62256ed8adbf48f21bc71de2e897359830e741d51359dc525ff9be5a14d044b0d09c4e9d25468ccd89db531e6ef91a5ae266a0af7012bef53a553c6
|
7
|
+
data.tar.gz: 50155220f312fa1f8de018a7ff43bb579195fb77b10b43c83c564e55264f32060155b865703fc9f30eedaa8c095507c794adf7df0cc1aed92d7c753a38544af7
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 toyama0919
|
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,123 @@
|
|
1
|
+
# fluent-plugin-file-sprintf
|
2
|
+
|
3
|
+
sprintf output file plugin for Fluentd.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
### td-agent(Linux)
|
8
|
+
|
9
|
+
/usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-file-sprintf
|
10
|
+
|
11
|
+
### td-agent(Mac)
|
12
|
+
|
13
|
+
sudo /usr/local/Cellar/td-agent/1.1.XX/bin/fluent-gem install fluent-plugin-file-sprintf
|
14
|
+
|
15
|
+
### fluentd only
|
16
|
+
|
17
|
+
gem install fluent-plugin-file-sprintf
|
18
|
+
|
19
|
+
|
20
|
+
## parameter
|
21
|
+
|
22
|
+
param | value|exsample
|
23
|
+
--------|------|------
|
24
|
+
compress|file compress gzip(default:true)|true
|
25
|
+
buffer_path|buffer file path(require)|/tmp/buffer/test.ltsv.*.log
|
26
|
+
path|output file path(require)|/tmp/test.ltsv
|
27
|
+
format|sprintf format(require)|%s
|
28
|
+
key_names|key names comma separator(require)|ltsv
|
29
|
+
time_format|time value output format(default:%Y-%m-%d %H:%M:%S)|%Y-%m-%d %H:%M:%S
|
30
|
+
file_size_limit|log rotate file size limit byte(default 8388608)|31457280
|
31
|
+
|
32
|
+
## key_names reserved words
|
33
|
+
|
34
|
+
param | value|
|
35
|
+
--------|------|
|
36
|
+
time|output time string
|
37
|
+
tag|output tag string
|
38
|
+
ltsv|output ltsv string
|
39
|
+
msgpack|output msgpack string
|
40
|
+
json|output json string
|
41
|
+
|
42
|
+
|
43
|
+
## Configuration Exsample(json format)
|
44
|
+
|
45
|
+
<match apache.json>
|
46
|
+
type file_sprintf
|
47
|
+
compress true
|
48
|
+
buffer_path /tmp/buffer/apache.json.*.log
|
49
|
+
path /tmp/apache.json
|
50
|
+
format %s
|
51
|
+
key_names json
|
52
|
+
file_size_limit 31457280
|
53
|
+
</match>
|
54
|
+
|
55
|
+
|
56
|
+
## Configuration Exsample(labeled tsv format)
|
57
|
+
|
58
|
+
<match apache.ltsv>
|
59
|
+
type file_sprintf
|
60
|
+
compress true
|
61
|
+
buffer_path /tmp/buffer/apache.ltsv.*.log
|
62
|
+
path /tmp/apache.ltsv
|
63
|
+
format %s
|
64
|
+
key_names ltsv
|
65
|
+
file_size_limit 31457280
|
66
|
+
</match>
|
67
|
+
|
68
|
+
## Configuration Exsample(message pack format)
|
69
|
+
|
70
|
+
<match apache.ltsv>
|
71
|
+
type file_sprintf
|
72
|
+
compress true
|
73
|
+
buffer_path /tmp/buffer/apache.msgpack.*.log
|
74
|
+
path /tmp/apache.msgpack
|
75
|
+
format %s
|
76
|
+
key_names msgpack
|
77
|
+
file_size_limit 31457280
|
78
|
+
</match>
|
79
|
+
|
80
|
+
## Configuration Exsample(custom json format)
|
81
|
+
|
82
|
+
<match apache.myjson>
|
83
|
+
type file_sprintf
|
84
|
+
compress true
|
85
|
+
buffer_path /tmp/buffer/apache.json.*.log
|
86
|
+
path /tmp/apache.json
|
87
|
+
format {"method":"%s","agent":"%s","referer":"%s","path":"%s","host":"%s","time":"%s","tag":"%s"}
|
88
|
+
key_names method,agent,referer,path,host,time,tag
|
89
|
+
file_size_limit 31457280
|
90
|
+
</match>
|
91
|
+
|
92
|
+
## Configuration Exsample(tsv format)
|
93
|
+
|
94
|
+
<match apache.tsv>
|
95
|
+
type file_sprintf
|
96
|
+
compress true
|
97
|
+
buffer_path /tmp/buffer/apache.tsv.*.log
|
98
|
+
path /tmp/apache.tsv
|
99
|
+
format %s\t%s\t%s\t%s\t%s\t%s\t%s
|
100
|
+
key_names method,agent,referer,path,host,time,tag
|
101
|
+
file_size_limit 31457280
|
102
|
+
</match>
|
103
|
+
|
104
|
+
## Configuration Exsample(elasticsearch bulk import format. multiline format)
|
105
|
+
|
106
|
+
<store>
|
107
|
+
type file_sprintf
|
108
|
+
compress false
|
109
|
+
buffer_path /tmp/buffer/es.json.*.log
|
110
|
+
path /tmp/es.json
|
111
|
+
format { "index" : { "_index" : "test_index", "_type" : "test_type" } }\n%s
|
112
|
+
key_names json
|
113
|
+
file_size_limit 31457280
|
114
|
+
</store>
|
115
|
+
|
116
|
+
|
117
|
+
## Contributing
|
118
|
+
|
119
|
+
1. Fork it
|
120
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
121
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
122
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
123
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "bundler"
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
Bundler::GemHelper.install_tasks
|
4
|
+
require 'rake/testtask'
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |test|
|
7
|
+
test.libs << 'lib' << 'test'
|
8
|
+
test.test_files = FileList['test/plugin/*.rb']
|
9
|
+
test.verbose = true
|
10
|
+
end
|
11
|
+
|
12
|
+
task :coverage do |t|
|
13
|
+
ENV['COVERAGE'] = '1'
|
14
|
+
Rake::Task["test"].invoke
|
15
|
+
end
|
16
|
+
|
17
|
+
task :default => [:build]
|
@@ -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-file-sprintf"
|
7
|
+
spec.version = "0.0.1"
|
8
|
+
spec.authors = ["Hiroshi Toyama"]
|
9
|
+
spec.email = ["toyama0919@gmail.com"]
|
10
|
+
spec.description = %q{sprintf output file plugin for Fluentd.}
|
11
|
+
spec.summary = spec.description
|
12
|
+
spec.homepage = "https://github.com/toyama0919/fluent-plugin-file-sprintf/"
|
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_runtime_dependency "ltsv"
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module Fluent
|
3
|
+
class FileSprintfOutput < Fluent::TimeSlicedOutput
|
4
|
+
Fluent::Plugin.register_output('file_sprintf', self)
|
5
|
+
|
6
|
+
config_param :path, :string
|
7
|
+
config_param :file_size_limit, :integer ,:default => 8388608
|
8
|
+
config_param :format, :string
|
9
|
+
config_param :compress, :bool, :default => true
|
10
|
+
config_param :key_names, :string
|
11
|
+
config_param :time_format, :string, :default => "%Y-%m-%d %H:%M:%S"
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
super
|
15
|
+
require 'zlib'
|
16
|
+
require 'ltsv'
|
17
|
+
end
|
18
|
+
|
19
|
+
def start
|
20
|
+
super
|
21
|
+
end
|
22
|
+
|
23
|
+
def shutdown
|
24
|
+
super
|
25
|
+
end
|
26
|
+
|
27
|
+
def configure(conf)
|
28
|
+
super
|
29
|
+
@key_names = @key_names.split(',').map{|key|
|
30
|
+
key = key.strip
|
31
|
+
result = ""
|
32
|
+
if key == 'time'
|
33
|
+
result = "Time.at(time).strftime('#{time_format}')"
|
34
|
+
elsif key == 'tag'
|
35
|
+
result = 'tag'
|
36
|
+
elsif key == 'ltsv'
|
37
|
+
result = 'LTSV.dump(record)'
|
38
|
+
elsif key == 'json'
|
39
|
+
result = 'record.to_json'
|
40
|
+
elsif key == 'msgpack'
|
41
|
+
result = 'record.to_msgpack'
|
42
|
+
else
|
43
|
+
result = "record['" + key + "']"
|
44
|
+
end
|
45
|
+
result
|
46
|
+
}
|
47
|
+
@key_names = @key_names.join(',')
|
48
|
+
@eval_string = "%Q{#{@format}} % [#{@key_names}]"
|
49
|
+
$log.info "format => #{@eval_string}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def format(tag, time, record)
|
53
|
+
[tag, time, record].to_msgpack
|
54
|
+
end
|
55
|
+
|
56
|
+
def write(chunk)
|
57
|
+
filepath = @path
|
58
|
+
file_size = 0
|
59
|
+
File.open(filepath,'a') { |file|
|
60
|
+
chunk.msgpack_each do |tag, time, record|
|
61
|
+
result = eval(@eval_string)
|
62
|
+
file.puts result
|
63
|
+
end
|
64
|
+
file_size = file.size
|
65
|
+
}
|
66
|
+
|
67
|
+
if file_size > @file_size_limit
|
68
|
+
if @compress
|
69
|
+
Zlib::GzipWriter.open(@path + "." + "#{Fluent::Engine.now}" + ".gz") do |gz|
|
70
|
+
gz.mtime = File.mtime(filepath)
|
71
|
+
gz.orig_name = filepath
|
72
|
+
gz.write IO.binread(filepath)
|
73
|
+
end
|
74
|
+
else
|
75
|
+
FileUtils.cp filepath, @path + "." + "#{Fluent::Engine.now}"
|
76
|
+
end
|
77
|
+
FileUtils.remove_file(filepath, force = true)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-file-sprintf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hiroshi Toyama
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ltsv
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
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: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: sprintf output file plugin for Fluentd.
|
56
|
+
email:
|
57
|
+
- toyama0919@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- fluent-plugin-file-sprintf.gemspec
|
68
|
+
- lib/fluent/plugin/out_file_sprintf.rb
|
69
|
+
homepage: https://github.com/toyama0919/fluent-plugin-file-sprintf/
|
70
|
+
licenses:
|
71
|
+
- MIT
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.2.0
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: sprintf output file plugin for Fluentd.
|
93
|
+
test_files: []
|