fluent-plugin-incremental 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NDJlZGRlYzAyODNlN2JmNjQ4NTliMWM3ZWQ5NjNjZTlkNDIwMjRlOQ==
5
+ data.tar.gz: !binary |-
6
+ MjljMjY1MmVjZWNjMTFlY2I1NTUzZjY4MTZmNzk2Y2Q3NWNiMzAxOA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZDhkYjFiMjdhZTViZjU1NDIzMzNlZDg4NTVkM2MwNzYxZmU4MWUwOGI0MjY1
10
+ NjM0YmUzYzAyNTZkYzhjYzM3YWM0Y2RkMzQ4N2E1OTAxNTgyMjE3MmU5ZDdk
11
+ MTBlMjNhYWIyOWQyNmM3OGJjOTVhZDZiNzhiMmM1MGM0YzJlMzQ=
12
+ data.tar.gz: !binary |-
13
+ OTM0NThlNTkwNzcxOTBjZjdmNWUwYjdiNmQ4MzlmMzhjMGFlMTliZTcyOGZh
14
+ YjU5NGFkMjg5YTE3ODE5Y2NjMTlkNWIzMmVlNTI2MmI5ODdiYTE4MGVlMmFi
15
+ YTgyNjM5NTEwZjlmNmJiNjEzMTZjOGYyNmU3N2Y4YjRkMjUxN2M=
@@ -0,0 +1,6 @@
1
+ Gemfile.lock
2
+ nbproject/
3
+ .project
4
+ *.gem
5
+ pkg
6
+ test/
@@ -0,0 +1,2 @@
1
+ eclipse.preferences.version=1
2
+ encoding/README.md=UTF-8
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-incremental.gemspec
4
+ gemspec
@@ -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.
@@ -0,0 +1,59 @@
1
+ # Fluent::Plugin::incremental
2
+
3
+ numeric incremental output plugin for Fluentd.
4
+
5
+ ## Installation
6
+
7
+ $ fluent-gem install fluent-plugin-incremental
8
+
9
+ ## parameter
10
+
11
+ param | value
12
+ --------|------
13
+ unit|reset cycle unit(year or month or day or hour or min)
14
+ incremental_file_path|incremental store file path
15
+ remove_tag_prefix|remove tag prefix
16
+ add_tag_prefix|add tag prefix
17
+ name_key_pattern|incremental column target , regular expression
18
+
19
+ ## result example
20
+
21
+ {"status_200_count" => "10","status_404_count" => "10"} # tag -> test.debug
22
+ #=> {"status_200_count" => "10","status_404_count" => "10"}
23
+
24
+ {"status_200_count" => "15","status_404_count" => "20"} # tag -> test.debug
25
+ #=> {"status_200_count" => "25","status_404_count" => "30"}
26
+
27
+ {"status_200_count" => "15","status_404_count" => "20"} # tag -> test2.debug
28
+ #=> {"status_200_count" => "15","status_404_count" => "20"}
29
+
30
+ {"status_200_count" => "20","status_404_count" => "30"} # tag -> test.debug
31
+ #=> {"status_200_count" => "45","status_404_count" => "60"}
32
+
33
+ {"status_200_count" => "15","status_404_count" => "20"} # tag -> test2.debug
34
+ #=> {"status_200_count" => "30","status_404_count" => "40"}
35
+
36
+
37
+ ## Configuration
38
+
39
+ <match test.*>
40
+ type incremental
41
+ unit hour
42
+ incremental_file_path /tmp/input
43
+ remove_tag_prefix test.
44
+ add_tag_prefix debug.
45
+ name_key_pattern .+_count$
46
+ </match>
47
+
48
+ <match debug.*>
49
+ type file
50
+ path /tmp/output
51
+ </match>
52
+
53
+ ## Contributing
54
+
55
+ 1. Fork it
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create new Pull Request
@@ -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,22 @@
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-incremental"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["toyama0919"]
9
+ spec.email = ["toyama0919@gmail.com"]
10
+ spec.description = %q{numeric incremental output plugin for Fluentd.}
11
+ spec.summary = spec.description
12
+ spec.homepage = "https://github.com/toyama0919/fluent-plugin-incremental/"
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 "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake"
22
+ end
@@ -0,0 +1,100 @@
1
+ module Fluent
2
+ class IncrementalOutput < Fluent::Output
3
+ Fluent::Plugin.register_output('incremental', self)
4
+
5
+ config_param :unit
6
+ config_param :incremental_file_path
7
+ config_param :add_tag_prefix
8
+ config_param :remove_tag_prefix
9
+ config_param :name_key_pattern, :default => nil
10
+
11
+ def initialize
12
+ Encoding.default_internal = "UTF-8"
13
+ super
14
+ end
15
+
16
+ def configure(conf)
17
+ super
18
+ if @unit.nil? || @unit.empty?
19
+ raise ConfigError, "incremental configure requires 'unit'"
20
+ else
21
+ if @unit != "hour" and @unit != "day" and @unit != "month" and @unit != "year" and @unit != "min"
22
+ raise ConfigError, "incremental configure unit allow year or month or day or hour or min"
23
+ end
24
+ end
25
+ if @incremental_file_path.nil? || @incremental_file_path.empty?
26
+ raise ConfigError, "incremental configure requires 'incremental_file_path'"
27
+ end
28
+ if @add_tag_prefix.nil? || @add_tag_prefix.empty?
29
+ raise ConfigError, "incremental configure requires 'add_tag_prefix'"
30
+ end
31
+ if @remove_tag_prefix.nil? || @remove_tag_prefix.empty?
32
+ raise ConfigError, "incremental configure requires 'remove_tag_prefix'"
33
+ end
34
+ @time_format = "%Y-%m-%d %H:%M:%S"
35
+ @timestamp_key = "last_updated"
36
+ end
37
+
38
+ def emit(tag, es, chain)
39
+ filepath = @incremental_file_path + "." + tag
40
+ result = get_result(filepath)
41
+ es.each do | time, record|
42
+ record.each {|key,value|
43
+ next if (value =~ /^[+-]?\d+$/) == nil
44
+ unless @name_key_pattern.nil?
45
+ next if key !~ /#{@name_key_pattern}/
46
+ end
47
+ result[key] = (result[key].nil? ? 0 : result[key]) + value.to_i
48
+ }
49
+ end
50
+ result[@timestamp_key] = Time.now.strftime(@time_format)
51
+ write_file(result,filepath)
52
+ result.delete(@timestamp_key)
53
+ Fluent::Engine.emit(tag.gsub(@remove_tag_prefix,@add_tag_prefix), Fluent::Engine.now, result)
54
+ end
55
+
56
+ private
57
+
58
+ def write_file(result,filepath)
59
+ dump = Marshal.dump(result)
60
+ File.open(filepath,'w') { |file|
61
+ file.print dump
62
+ file.close
63
+ }
64
+ end
65
+
66
+ def get_result(filepath)
67
+ if File.exist?(filepath)
68
+ if File.read(filepath).size == 0
69
+ result = Hash.new
70
+ else
71
+ result = Marshal.load(File.read(filepath))
72
+ if @unit == 'year'
73
+ if Time.now.year != Time.strptime(result[@timestamp_key],@time_format).year
74
+ result = Hash.new
75
+ end
76
+ elsif @unit == 'month'
77
+ if Time.now.month != Time.strptime(result[@timestamp_key],@time_format).month
78
+ result = Hash.new
79
+ end
80
+ elsif @unit == 'day'
81
+ if Time.now.day != Time.strptime(result[@timestamp_key],@time_format).day
82
+ result = Hash.new
83
+ end
84
+ elsif @unit == 'hour'
85
+ if Time.now.hour != Time.strptime(result[@timestamp_key],@time_format).hour
86
+ result = Hash.new
87
+ end
88
+ elsif @unit == 'min'
89
+ if Time.now.min != Time.strptime(result[@timestamp_key],@time_format).min
90
+ result = Hash.new
91
+ end
92
+ end
93
+ end
94
+ else # not exist file
95
+ result = Hash.new
96
+ end
97
+ return result
98
+ end
99
+ end
100
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-incremental
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - toyama0919
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-14 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: numeric incremental output plugin for Fluentd.
42
+ email:
43
+ - toyama0919@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - .settings/org.eclipse.core.resources.prefs
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - fluent-plugin-incremental.gemspec
55
+ - lib/fluent/plugin/out_incremental.rb
56
+ homepage: https://github.com/toyama0919/fluent-plugin-incremental/
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.1.8
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: numeric incremental output plugin for Fluentd.
80
+ test_files: []