fluent-plugin-file-sprintf 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d163ac14dd07900df0593a1f4af13c36c0e8f90
4
- data.tar.gz: 3dd2e2847944b971e4282f5fd677e078338c164c
3
+ metadata.gz: 1ba817afaccb6b510811ffb6855dd56d498dd967
4
+ data.tar.gz: 4528ecde8a9397a30d29075aed0e32285638d50e
5
5
  SHA512:
6
- metadata.gz: c81ea6d448be12f508575718c6984e7a745bdeb447ecfd8336fb8795e6e5467f98caa4dba7be9ab6c4d1ae577ff5f7824516b629c6ca79f0dad581a9a88d57f1
7
- data.tar.gz: e4b654ae0bd9045b9d38a7014136880c934df7772ae1e64c5e83b28c80d80ef98f5319e988108726e3703f40cd9322685c47559052c14c90f75982ebda453f98
6
+ metadata.gz: 2a992d7e22d56f32a0f0f1f04ca0d149a6ebfa8ceee74be29d28281d0e2cf0fcfff4d0f39556daefbc7bc296c82d80fa203c8577e9e15efc36d91f0efa42d09b
7
+ data.tar.gz: 23211010a1fec9519c423ce62b8cfe582826abfc7e0d22fff0bd31a9f62007bd6cebb89e98298297b260ba7b047451bca43adc91c5cd34a1c227c5e06b708abd
data/README.md CHANGED
@@ -26,11 +26,11 @@ path|output file path(require)|/tmp/test.ltsv
26
26
  format|sprintf format(require)|%s
27
27
  key_names|key names comma separator(require)|ltsv
28
28
  time_format|time value output format(default:%Y-%m-%d %H:%M:%S)|%Y-%m-%d %H:%M:%S
29
- file_size_limit|log rotate file size limit byte(default 8388608)|31457280
30
29
  include_tag_key|tag key in record|true
31
30
  tag_key_name|tag key name(default:tag)|tag_name
32
31
  include_time_key|time key in record|true
33
32
  time_key_name|time key name(default:time)|timestamp
33
+ rotate_format|file rotate format(default:%Y%m%d)|%Y%m%d
34
34
 
35
35
  ## key_names reserved words
36
36
 
@@ -52,10 +52,8 @@ json|output json string
52
52
  path /tmp/apache.json
53
53
  format %s
54
54
  key_names json
55
- file_size_limit 31457280
56
55
  </match>
57
56
 
58
-
59
57
  ## Configuration Exsample(labeled tsv format)
60
58
 
61
59
  <match apache.ltsv>
@@ -65,7 +63,6 @@ json|output json string
65
63
  path /tmp/apache.ltsv
66
64
  format %s
67
65
  key_names ltsv
68
- file_size_limit 31457280
69
66
  </match>
70
67
 
71
68
  ## Configuration Exsample(message pack format)
@@ -77,7 +74,6 @@ json|output json string
77
74
  path /tmp/apache.msgpack
78
75
  format %s
79
76
  key_names msgpack
80
- file_size_limit 31457280
81
77
  </match>
82
78
 
83
79
  ## Configuration Exsample(custom json format)
@@ -89,7 +85,6 @@ json|output json string
89
85
  path /tmp/apache.json
90
86
  format {"method":"%s","agent":"%s","referer":"%s","path":"%s","host":"%s","time":"%s","tag":"%s"}
91
87
  key_names method,agent,referer,path,host,time,tag
92
- file_size_limit 31457280
93
88
  </match>
94
89
 
95
90
  ## Configuration Exsample(tsv format)
@@ -101,7 +96,6 @@ json|output json string
101
96
  path /tmp/apache.tsv
102
97
  format %s\t%s\t%s\t%s\t%s\t%s\t%s
103
98
  key_names method,agent,referer,path,host,time,tag
104
- file_size_limit 31457280
105
99
  </match>
106
100
 
107
101
  ## Configuration Exsample(elasticsearch bulk import format. multiline format)
@@ -113,7 +107,6 @@ json|output json string
113
107
  path /tmp/es.json
114
108
  format { "index" : { "_index" : "test_index", "_type" : "test_type" } }\n%s
115
109
  key_names json
116
- file_size_limit 31457280
117
110
  </store>
118
111
 
119
112
 
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "fluent-plugin-file-sprintf"
7
- spec.version = "0.0.3"
7
+ spec.version = "0.0.4"
8
8
  spec.authors = ["Hiroshi Toyama"]
9
9
  spec.email = ["toyama0919@gmail.com"]
10
10
  spec.description = %q{sprintf output file plugin for Fluentd.}
@@ -4,7 +4,6 @@ module Fluent
4
4
  Fluent::Plugin.register_output('file_sprintf', self)
5
5
 
6
6
  config_param :path, :string
7
- config_param :file_size_limit, :integer ,:default => 8388608
8
7
  config_param :format, :string
9
8
  config_param :compress, :bool, :default => true
10
9
  config_param :include_tag_key, :bool, :default => false
@@ -13,6 +12,8 @@ module Fluent
13
12
  config_param :time_key_name, :string, :default => "time"
14
13
  config_param :key_names, :string
15
14
  config_param :time_format, :string, :default => "%Y-%m-%d %H:%M:%S"
15
+ config_param :rotate_format, :string, :default => "%Y%m%d"
16
+ config_param :file_prefix_key, :string, :default => "Time.at(time).strftime(@rotate_format)"
16
17
 
17
18
  def initialize
18
19
  super
@@ -51,6 +52,7 @@ module Fluent
51
52
  @key_names = @key_names.join(',')
52
53
  @eval_string = "%Q{#{@format}} % [#{@key_names}]"
53
54
  $log.info "format => #{@eval_string}"
55
+ $log.info "flush_interval => #{@flush_interval}"
54
56
  end
55
57
 
56
58
  def format(tag, time, record)
@@ -64,28 +66,45 @@ module Fluent
64
66
  end
65
67
 
66
68
  def write(chunk)
67
- filepath = @path
68
- file_size = 0
69
- File.open(filepath,'a') { |file|
70
- chunk.msgpack_each do |tag, time, record|
71
- result = eval(@eval_string)
72
- file.puts result
73
- end
74
- file_size = file.size
69
+ write_file(chunk)
70
+ compress_file
71
+ end
72
+
73
+ private
74
+ def write_file(chunk)
75
+ set = Set.new
76
+ chunk.msgpack_each do |tag, time, record|
77
+ set.add(eval(@file_prefix_key))
78
+ end
79
+
80
+ filename_hash = {}
81
+ set.each{|prefix|
82
+ filename_hash[prefix] = File.open(@path + '.' + prefix,'a')
83
+ }
84
+
85
+ chunk.msgpack_each do |tag, time, record|
86
+ result = eval(@eval_string)
87
+ file = filename_hash[eval(@file_prefix_key)]
88
+ file.puts result
89
+ end
90
+
91
+ filename_hash.each{|k,v|
92
+ v.close
75
93
  }
94
+ end
76
95
 
77
- if file_size > @file_size_limit
78
- output_path = @path + "." + "#{Time.now.strftime('%Y%m%d%H%M%S')}"
79
- if @compress
80
- Zlib::GzipWriter.open(output_path + ".gz") do |gz|
81
- gz.mtime = File.mtime(filepath)
82
- gz.orig_name = filepath
83
- gz.write IO.binread(filepath)
96
+ def compress_file
97
+ if @compress
98
+ Dir.glob( "#{@path}.*[^gz]" ).each{ |output_path|
99
+ if Time.now > File.mtime(output_path) + (@flush_interval * 5)
100
+ Zlib::GzipWriter.open(output_path + ".gz") do |gz|
101
+ gz.mtime = File.mtime(output_path)
102
+ gz.orig_name = output_path
103
+ gz.write IO.binread(output_path)
104
+ end
105
+ FileUtils.remove_file(output_path, force = true)
84
106
  end
85
- else
86
- FileUtils.cp filepath, output_path
87
- end
88
- FileUtils.remove_file(filepath, force = true)
107
+ }
89
108
  end
90
109
  end
91
110
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-file-sprintf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroshi Toyama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-15 00:00:00.000000000 Z
11
+ date: 2014-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ltsv
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  version: '0'
87
87
  requirements: []
88
88
  rubyforge_project:
89
- rubygems_version: 2.2.0.rc.1
89
+ rubygems_version: 2.2.0
90
90
  signing_key:
91
91
  specification_version: 4
92
92
  summary: sprintf output file plugin for Fluentd.