fluent-plugin-growthforecast 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
@@ -0,0 +1,52 @@
1
+ # rcov generated
2
+ coverage
3
+
4
+ # rdoc generated
5
+ rdoc
6
+
7
+ # yard generated
8
+ doc
9
+ .yardoc
10
+
11
+ # bundler
12
+ .bundle
13
+
14
+ # jeweler generated
15
+ pkg
16
+
17
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
18
+ #
19
+ # * Create a file at ~/.gitignore
20
+ # * Include files you want ignored
21
+ # * Run: git config --global core.excludesfile ~/.gitignore
22
+ #
23
+ # After doing this, these files will be ignored in all your git projects,
24
+ # saving you from having to 'pollute' every project you touch with them
25
+ #
26
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
27
+ #
28
+ # For MacOS:
29
+ #
30
+ .DS_Store
31
+
32
+ # For TextMate
33
+ *.tmproj
34
+ tmtags
35
+
36
+ # For emacs:
37
+ *~
38
+ \#*
39
+ .\#*
40
+
41
+ # For vim:
42
+ *.swp
43
+
44
+ # For redcar:
45
+ #.redcar
46
+
47
+ # For rubinius:
48
+ #*.rbc
49
+
50
+ Gemfile.lock
51
+ vendor
52
+
data/AUTHORS ADDED
@@ -0,0 +1 @@
1
+ TAGOMORI Satoshi <tagomoris _at_ gmail.com>
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.6.4"
12
+ gem "simplecov", ">= 0"
13
+ end
14
+
15
+ gem "fluentd"
16
+ gem "rdoc"
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2012- TAGOMORI Satoshi
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,59 @@
1
+ = fluent-plugin-growthforecast
2
+
3
+ == Component
4
+
5
+ === GrowthForecastOutput
6
+
7
+ Plugin to output numbers(metrics) to 'GrowthForecast', metrics drawing tool over HTTP.
8
+
9
+ About GrowthForecast, see:
10
+ - Github: https://github.com/kazeburo/growthforecast
11
+ - Japanese blog post by @kazeburo: http://blog.nomadscafe.jp/2011/12/growthforecast.html
12
+
13
+ GrowthForecast is very simple but useful tool to draw graphs what we want, with GrowthForecastOutput and Fluentd.
14
+
15
+ == Configuration
16
+
17
+ === GrowthForecastOutput
18
+
19
+ For messages such as:
20
+ tag:metrics {"field1":300, "field2":20, "field3diff":-30}
21
+
22
+ Configuration example for graphs in growthforecast with POST api url 'http://growthforecast.local/api/service1/metrics1/metrics_FIELDNAME'.
23
+
24
+ <match metrics>
25
+ type growthforecast
26
+ gfapi_url http://growthforecast.local/api/
27
+ service service1
28
+ section metrics1
29
+ name_keys field1,field2,field3diff
30
+ </match>
31
+
32
+ With this configuration, out_growthforecast posts urls below.
33
+ - http://growthforecast.local/api/service1/metrics1/metrics_field1
34
+ - http://growthforecast.local/api/service1/metrics1/metrics_field2
35
+ - http://growthforecast.local/api/service1/metrics1/metrics_field3diff
36
+
37
+
38
+ If you want to use tags for 'section' in GrowthForecast, use 'tag_for' options and remove_prefix (and not to set 'section').
39
+
40
+ <match metrics.**>
41
+ type growthforecast
42
+ gfapi_url http://growthforecast.local/api/
43
+ service service1
44
+ name_keys field1,field2,field3diff
45
+ tag_for section # or 'name_prefix'(default) or 'ignore'
46
+ remove_prefix metrics
47
+ </match>
48
+
49
+ 'mode' option available with 'gauge'(default), 'count', 'modified', just same as 'mode' of GrowthForecast POST parameter.
50
+
51
+ == TODO
52
+
53
+ - consider what to do next
54
+ - patches welcome!
55
+
56
+ == Copyright
57
+
58
+ Copyright:: Copyright (c) 2012- TAGOMORI Satoshi (tagomoris)
59
+ License:: Apache License, Version 2.0
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "fluent-plugin-growthforecast"
18
+ gem.description = "Plugin to post numbers to GrowthForecast (by kazeburo)"
19
+ gem.homepage = "http://github.com/tagomoris/fluent-plugin-growthforecast"
20
+ gem.summary = gem.description
21
+ gem.email = "tagomoris@gmail.com"
22
+ gem.authors = ["TAGOMORI Satoshi"]
23
+ gem.has_rdoc = "false"
24
+ # dependencies defined in Gemfile
25
+ gem.files = `git ls-files`.split("\n")
26
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
27
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
28
+ gem.require_paths = ['lib']
29
+ gem.add_dependency "fluentd", "~> 0.10.8"
30
+ gem.add_development_dependency "rake", ">= 0.9.2"
31
+ gem.add_development_dependency "simplecov", ">= 0.5.4"
32
+ end
33
+ Jeweler::RubygemsDotOrgTasks.new
34
+
35
+ require 'rake/testtask'
36
+ Rake::TestTask.new(:test) do |test|
37
+ test.libs << 'lib' << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ end
41
+
42
+ task :default => :test
43
+
44
+ require 'rdoc/task'
45
+ Rake::RDocTask.new do |rdoc|
46
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "fluent-plugin-growthforecast #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,95 @@
1
+ class Fluent::GrowthForecastOutput < Fluent::Output
2
+ Fluent::Plugin.register_output('growthforecast', self)
3
+
4
+ def initialize
5
+ super
6
+ require 'net/http'
7
+ require 'uri'
8
+ end
9
+
10
+ config_param :gfapi_url, :string # growth.forecast.local/api/
11
+ config_param :service, :string
12
+ config_param :section, :string, :default => nil
13
+ config_param :name_keys, :string
14
+
15
+ config_param :mode, :string, :default => 'gauge' # or count/modified
16
+
17
+ config_param :remove_prefix, :string, :default => nil
18
+ config_param :tag_for, :string, :default => 'name_prefix' # or 'ignore' or 'section'
19
+
20
+ def configure(conf)
21
+ super
22
+
23
+ if @gfapi_url !~ /\/api\/\Z/
24
+ raise Fluent::ConfigError, "gfapi_url must end with /api/"
25
+ end
26
+ @gfurl = @gfapi_url + @service + '/'
27
+
28
+ @mode = case @mode
29
+ when 'count' then :count
30
+ when 'modified' then :modified
31
+ else
32
+ :gauge
33
+ end
34
+ @tag_for = case @tag_for
35
+ when 'ignore' then :ignore
36
+ when 'section' then :section
37
+ else
38
+ :name_prefix
39
+ end
40
+ if @tag_for != :section and @section.nil?
41
+ raise Fluent::ConfigError, "section parameter is needed when tag_for is not 'section'"
42
+ end
43
+
44
+ if @remove_prefix
45
+ @removed_prefix_string = @remove_prefix + '.'
46
+ @removed_length = @removed_prefix_string.length
47
+ end
48
+ @name_keys = @name_keys.split(',')
49
+ end
50
+
51
+ def start
52
+ super
53
+ end
54
+
55
+ def shutdown
56
+ super
57
+ end
58
+
59
+ def format_url(tag, name)
60
+ case @tag_for
61
+ when :ignore
62
+ @gfurl + @section + '/' + name
63
+ when :section
64
+ @gfurl + tag + '/' + name
65
+ when :name_prefix
66
+ @gfurl + @section + '/' + tag + '_' + name
67
+ end
68
+ end
69
+
70
+ def post(tag, name, value)
71
+ url = format_url(tag,name)
72
+ res = Net::HTTP.post_form(URI.parse(url), {'number' => value.to_i, 'mode' => @mode.to_s})
73
+ case res
74
+ when Net::HTTPSuccess
75
+ # OK
76
+ else
77
+ $log.warn "failed to post to growthforecast: #{url}, number: #{value}, code: #{res.code}"
78
+ end
79
+ end
80
+
81
+ def emit(tag, es, chain)
82
+ if @remove_prefix and
83
+ ( (tag.start_with?(@removed_prefix_string) and tag.length > @removed_length) or tag == @remove_prefix)
84
+ tag = tag[@removed_length..-1]
85
+ end
86
+ es.each {|time,record|
87
+ @name_keys.each {|name|
88
+ if record[name]
89
+ post(tag, name, record[name])
90
+ end
91
+ }
92
+ }
93
+ chain.next
94
+ end
95
+ end
@@ -0,0 +1,19 @@
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
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'fluent/test'
16
+ require 'fluent/plugin/out_growthforecast'
17
+
18
+ class Test::Unit::TestCase
19
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestFluentPluginGrowthforecast < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-growthforecast
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - TAGOMORI Satoshi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-18 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: fluentd
16
+ requirement: &2160082200 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2160082200
25
+ - !ruby/object:Gem::Dependency
26
+ name: rdoc
27
+ requirement: &2160081720 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2160081720
36
+ - !ruby/object:Gem::Dependency
37
+ name: shoulda
38
+ requirement: &2160081240 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2160081240
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: &2160080760 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2160080760
58
+ - !ruby/object:Gem::Dependency
59
+ name: jeweler
60
+ requirement: &2160080280 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 1.6.4
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *2160080280
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: &2160079800 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *2160079800
80
+ - !ruby/object:Gem::Dependency
81
+ name: fluentd
82
+ requirement: &2160079320 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: 0.10.8
88
+ type: :runtime
89
+ prerelease: false
90
+ version_requirements: *2160079320
91
+ - !ruby/object:Gem::Dependency
92
+ name: rake
93
+ requirement: &2160078840 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: 0.9.2
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *2160078840
102
+ - !ruby/object:Gem::Dependency
103
+ name: simplecov
104
+ requirement: &2160078360 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: 0.5.4
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *2160078360
113
+ description: Plugin to post numbers to GrowthForecast (by kazeburo)
114
+ email: tagomoris@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files:
118
+ - LICENSE.txt
119
+ - README.rdoc
120
+ files:
121
+ - .document
122
+ - .gitignore
123
+ - AUTHORS
124
+ - Gemfile
125
+ - LICENSE.txt
126
+ - README.rdoc
127
+ - Rakefile
128
+ - VERSION
129
+ - lib/fluent/plugin/out_growthforecast.rb
130
+ - test/helper.rb
131
+ - test/plugin/test_out_growthforecast.rb
132
+ homepage: http://github.com/tagomoris/fluent-plugin-growthforecast
133
+ licenses: []
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ! '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ segments:
145
+ - 0
146
+ hash: -1863730412705014917
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ none: false
149
+ requirements:
150
+ - - ! '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 1.8.6
156
+ signing_key:
157
+ specification_version: 3
158
+ summary: Plugin to post numbers to GrowthForecast (by kazeburo)
159
+ test_files:
160
+ - test/helper.rb
161
+ - test/plugin/test_out_growthforecast.rb