fluent-plugin-cloudwatch 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-cloudwatch.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Yusuke Nomura
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.rdoc ADDED
@@ -0,0 +1,49 @@
1
+ = Fluent::Plugin::Cloudwatch
2
+
3
+ Plugin for AWS CloudWatch.
4
+
5
+ == Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'fluent-plugin-cloudwatch'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install fluent-plugin-cloudwatch
18
+
19
+ == Configuration
20
+
21
+ <source>
22
+ type cloudwatch
23
+ tag cloudwatch
24
+ access_key XXXXXXXXXX
25
+ secret_key XXXXXXXXXX
26
+ endpoint monitoring.ap-northeast-1.amazonaws.com
27
+
28
+ <metric>
29
+ namespace AWS/EC2
30
+ statistics Average
31
+ dimensions InstanceId=i-xxxxxxxx
32
+ metric_name CPUUtilization
33
+ </metric>
34
+ <metric>
35
+ namespace AWS/EC2
36
+ statistics Sum
37
+ dimensions InstanceId=i-xxxxxxxx
38
+ metric_name NetworkIn
39
+ </metric>
40
+ </source>
41
+
42
+
43
+ == Contributing
44
+
45
+ 1. Fork it
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require "rake/testtask"
5
+ Rake::TestTask.new(:test) do |test|
6
+ test.libs << 'lib' << 'test'
7
+ test.pattern = 'test/**/test_*.rb'
8
+ test.verbose = true
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Yusuke Nomura"]
6
+ gem.email = ["yunomu@gmail.com"]
7
+ gem.description = %q{Input plugin for AWS CloudWatch.}
8
+ gem.summary = %q{Input plugin for AWS CloudWatch}
9
+ gem.homepage = "https://github.com/yunomu/fluent-plugin-cloudwatch"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "fluent-plugin-cloudwatch"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = "1.0.0"
17
+
18
+ gem.add_development_dependency "fluentd"
19
+ gem.add_runtime_dependency "fluentd"
20
+ end
@@ -0,0 +1,77 @@
1
+ class Fluent::CloudwatchInput < Fluent::Input
2
+ Fluent::Plugin.register_input("cloudwatch", self)
3
+
4
+ config_param :tag, :string
5
+ config_param :access_key, :string
6
+ config_param :secret_key, :string
7
+ config_param :endpoint, :string, :default => "monitoring.amazonaws.com"
8
+
9
+ def initialize
10
+ super
11
+ require 'rubygems'
12
+ require 'AWS'
13
+ require 'time'
14
+ end
15
+
16
+ def configure(conf)
17
+ super
18
+ @mon = AWS::Cloudwatch::Base.new(
19
+ :access_key_id => access_key,
20
+ :secret_access_key => secret_key,
21
+ :server => endpoint)
22
+
23
+ @metrics = conf.elements.select {|e|
24
+ e.name == 'metric'
25
+ }.map {|e|
26
+ {:namespace => e['namespace'],
27
+ :statistics => e['statistics'],
28
+ :dimensions => e['dimensions'],
29
+ :measure_name => e['metric_name']}
30
+ }
31
+ end
32
+
33
+ def start
34
+ super
35
+ @watcher = Thread.new(&method(:watch))
36
+ end
37
+
38
+ def shutdown
39
+ super
40
+ @watcher.terminate
41
+ @watcher.join
42
+ end
43
+
44
+ private
45
+ def watch
46
+ while true
47
+ Fluent::Engine.emit(tag, Fluent::Engine.now, output)
48
+ sleep 60 * 5
49
+ end
50
+ end
51
+
52
+ def output
53
+ end_time = Time.now
54
+ start_time = end_time - 60 * 60
55
+ @metrics.map {|m|
56
+ m[:start_time] = start_time
57
+ m[:end_time] = end_time
58
+ format m, @mon.get_metric_statistics(m)
59
+ }
60
+ end
61
+
62
+ def format(m, s)
63
+ d = s["GetMetricStatisticsResult"]["Datapoints"]["member"].sort {|a,b|
64
+ time(a) <=> time(b)
65
+ }.last
66
+
67
+ d["MetricName"] = m[:measure_name]
68
+ d["Statistics"] = m[:statistics]
69
+ d["Value"] = d.delete(m[:statistics])
70
+ d
71
+ end
72
+
73
+ def time(d)
74
+ Time.parse d["Timestamp"]
75
+ end
76
+ end
77
+
data/test/helper.rb ADDED
@@ -0,0 +1,30 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+ require "test/unit"
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require "fluent/test"
16
+ unless ENV.has_key?("VERBOSE")
17
+ nulllogger = Object.new
18
+ nulllogger.instance_eval {|obj|
19
+ def method_missing(method, *args)
20
+ #pass
21
+ end
22
+ }
23
+ $log = nulllogger
24
+ end
25
+
26
+ require "fluent/plugin/in_cloudwatch"
27
+
28
+ class Test::Unit::TestCase
29
+ end
30
+
@@ -0,0 +1,25 @@
1
+ require 'helper'
2
+
3
+ class CloudwatchInputTest < Test::Unit::TestCase
4
+ def setup
5
+ Fluent::Test.setup
6
+ end
7
+
8
+ CONFIG = %[
9
+ ]
10
+
11
+ def create_driver(conf = CONFIG, tag = 'test')
12
+ Fluent::Test::InputTestDriver.new(Fluent::CloudwatchInput).configure(conf)
13
+ end
14
+
15
+ def test_configure
16
+ end
17
+
18
+ def test_format
19
+ d = create_driver
20
+ end
21
+
22
+ def test_write
23
+ d = create_driver
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-cloudwatch
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yusuke Nomura
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: fluentd
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: fluentd
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Input plugin for AWS CloudWatch.
47
+ email:
48
+ - yunomu@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE
56
+ - README.rdoc
57
+ - Rakefile
58
+ - fluent-plugin-cloudwatch.gemspec
59
+ - lib/fluent/plugin/in_cloudwatch.rb
60
+ - test/helper.rb
61
+ - test/plugin/test_in_cloudwatch.rb
62
+ homepage: https://github.com/yunomu/fluent-plugin-cloudwatch
63
+ licenses: []
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.23
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Input plugin for AWS CloudWatch
86
+ test_files:
87
+ - test/helper.rb
88
+ - test/plugin/test_in_cloudwatch.rb