observed-fluentd 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.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ Mzk0ZDk4MjcyODVhNmQzMTM5ZDgzN2E1YzE1YTdiMWE0M2NlZjA1ZQ==
5
+ data.tar.gz: !binary |-
6
+ ZmU4Mzg5OThlZDU1MWZjYTJhMDcyMThmODY2NDFiZGY5MjI0MGE3Zg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZTAzZjY2MDBlYmUxYjYxNDU1YWNkYzFjMmEyMDc3OGUwYTQwZTk5ZDdjYzU3
10
+ N2VmZDEwYjQ1OTQ5YzIxZDBkYTRiMzU3YjI1YjdjODE5ODdhZTc0OTFiNzA2
11
+ NGFkNzhkZDYzNDM5NjUxNjJkZTJlNjZiZGVlMWFiMGVhYjllZjY=
12
+ data.tar.gz: !binary |-
13
+ ODgwNDNhNWQ3Yzc0YTIxY2EzYzZiMDdiZjY0OGY5ZWYwZTY0NDgyMTI5NjMz
14
+ NmQxMTUyZjZkMjY3MjkyMzA1YTlhNDA1ZWFmZmZhNjA4NjA4YTYwYzMyMDVj
15
+ OGI4YjU4ZmNkM2FmOTFmYTk2OWI3ODcyZDVkYjE1ODM3ODExNmM=
data/.gitignore ADDED
@@ -0,0 +1,20 @@
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
18
+ *~
19
+ *.log
20
+ bin/
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in observed-fluentd.gemspec
4
+ gemspec
5
+
6
+ gem 'clockwork', :group => :test
7
+ gem 'fluentd', :group => :test
8
+ gem 'cucumber', :group => :test
9
+ gem 'aruba', :group => :test
10
+ gem 'observed', :group => :test
11
+ gem 'observed-http', :group => :test
12
+ gem 'observed-clockwork', :group => :test
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 GREE, Inc.
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,99 @@
1
+ # Observed::Fluentd
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'observed-fluentd'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install observed-fluentd
18
+
19
+ Or `git clone` the sources and install by using rake:
20
+
21
+ $ rake install
22
+
23
+ ## Usage
24
+
25
+ First of all, we need to install the fluentd to which we send observed data:
26
+
27
+ $ gem install fluentd
28
+
29
+ Then we should configure Fluentd to see data which will be sent from observed-fluentd:
30
+
31
+ $ fluentd --setup fluent.d
32
+ Installed fluent.d/fluent.conf.
33
+
34
+ Ensure that the following 2 parts exist in the generated fluent.conf:
35
+
36
+ <source>
37
+ type forward
38
+ </source>
39
+
40
+ <match debug.**>
41
+ type stdout
42
+ </match>
43
+
44
+ Now we can run Fluentd:
45
+
46
+ $ fluentd -c fluent.d/fluent.conf
47
+
48
+ Install observed-fluentd:
49
+
50
+ $ gem build observed-fluentd.gemspec
51
+ $ gem install observed-fluentd
52
+ $ gem install observed-http
53
+ $ gem install observed-clockwork
54
+
55
+ Create the observed.conf like:
56
+
57
+ require 'observed/builtin_plugins'
58
+ require 'observed/http'
59
+ require 'observed/fluentd'
60
+
61
+ observe 'myservice', {
62
+ plugin: 'http',
63
+ method: 'get',
64
+ url: 'http://localhost/',
65
+ timeout_in_milliseconds: 3000,
66
+ }
67
+
68
+ match /myservice.*/, {
69
+ plugin: 'fluentd',
70
+ host: 'localhost',
71
+ port: 24224,
72
+ tag: 'debug.myservice'
73
+ }
74
+
75
+ Run clockwork and trigger observed:
76
+
77
+ $ cd observe.d/
78
+ $ clockwork clockwork.rb
79
+
80
+ Find data sent from Observed in the Fluentd output:
81
+
82
+ 2013-11-01T07:55:09Z debug.myservice {"status":"success","result":"Get http://localhost/","elapsed_time":0.013686}
83
+
84
+ Now you can do anything utilizing Fluent's rich features and plugins.
85
+
86
+ ## Developping
87
+
88
+ To run cucumber tests, execute:
89
+
90
+ $ bundle install --binstubs
91
+ $ bin/cucumber features
92
+
93
+ ## Contributing
94
+
95
+ 1. Fork it
96
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
97
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
98
+ 4. Push to the branch (`git push origin my-new-feature`)
99
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,61 @@
1
+ Feature: Receives Observed's input and send it to Fluentd
2
+
3
+ In order to pass data from Observed to Fluentd
4
+
5
+ I want to configure Observed to use observed-fluentd plugin
6
+
7
+ Scenario: Write configuration files for Observed and Fluentd, then run Fluentd, and then run Observed
8
+ Given a file named "test.rb" with:
9
+ """
10
+ require 'observed'
11
+ require 'observed/http'
12
+ require 'observed/fluentd'
13
+
14
+ include Observed
15
+
16
+ observe 'myservice', via: 'http', with: {
17
+ method: 'get',
18
+ url: 'http://google.com/',
19
+ timeout_in_milliseconds: 3000,
20
+ }
21
+
22
+ report /myservice.*/, via: 'fluentd', with: {
23
+ host: 'localhost',
24
+ port: 24224,
25
+ tag: 'debug.myservice'
26
+ }
27
+
28
+ run 'myservice'
29
+ """
30
+ Given a file named "fluent.conf" with:
31
+ """
32
+ <source>
33
+ type forward
34
+ </source>
35
+
36
+ <match debug.**>
37
+ type file
38
+ path fluent.out
39
+ time_slice_format foo
40
+ utc
41
+ flush_interval 1s
42
+ </match>
43
+ """
44
+ When I run `pwd`
45
+ When I run `fluentd -d pid_file -c fluent.conf`
46
+ # When I start my daemon with "fluentd -c tmp/aruba/fluent.conf"
47
+ When I run `sleep 3`
48
+ When I run `ruby test.rb`
49
+ #Then a daemon called "fluentd" should be running
50
+ When I run `sleep 3`
51
+ When I run the command "kill $(cat tmp/aruba/pid_file)"
52
+ When I run `cat fluent.out.foo_0.log`
53
+ Then the output should contain:
54
+ """
55
+ elapsed_time
56
+ """
57
+ Then the output should contain:
58
+ """
59
+ debug.myservice
60
+ """
61
+
@@ -0,0 +1,32 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'aruba/cucumber'
3
+
4
+ World(Aruba::Api)
5
+
6
+ Before do
7
+ @aruba_timeout_seconds = 120
8
+ end
9
+
10
+ When /^I run the command "([^"]+)"$/ do |cmd|
11
+ system cmd
12
+ end
13
+
14
+ When /^I start my daemon with "([^"]*)"$/ do |cmd|
15
+ @root = Pathname.new(File.dirname(__FILE__)).parent.parent.expand_path
16
+ command = "#{@root.join('bin')}/#{cmd}"
17
+
18
+ puts "In the working directory: #{Dir.pwd}"
19
+ puts "Running #{command}"
20
+
21
+ @pipe = IO.popen(command, "r")
22
+ sleep 2 # so the daemon has a chance to boot
23
+
24
+ # clean up the daemon when the tests finish
25
+ at_exit do
26
+ Process.kill("KILL", @pipe.pid)
27
+ end
28
+ end
29
+
30
+ Then /^a daemon called "([^"]*)" should be running$/ do |daemon|
31
+ `ps -eo command |grep #{daemon}`.size.should > 0
32
+ end
@@ -0,0 +1,93 @@
1
+
2
+ ## built-in TCP input
3
+ ## $ echo <json> | fluent-cat <tag>
4
+ <source>
5
+ type forward
6
+ </source>
7
+
8
+ ## built-in UNIX socket input
9
+ #<source>
10
+ # type unix
11
+ #</source>
12
+
13
+ # HTTP input
14
+ # http://localhost:8888/<tag>?json=<json>
15
+ <source>
16
+ type http
17
+ port 8888
18
+ </source>
19
+
20
+ ## File input
21
+ ## read apache logs with tag=apache.access
22
+ #<source>
23
+ # type tail
24
+ # format apache
25
+ # path /var/log/httpd-access.log
26
+ # tag apache.access
27
+ #</source>
28
+
29
+ # Listen HTTP for monitoring
30
+ # http://localhost:24220/api/plugins
31
+ # http://localhost:24220/api/plugins?type=TYPE
32
+ # http://localhost:24220/api/plugins?tag=MYTAG
33
+ <source>
34
+ type monitor_agent
35
+ port 24220
36
+ </source>
37
+
38
+ # Listen DRb for debug
39
+ <source>
40
+ type debug_agent
41
+ port 24230
42
+ </source>
43
+
44
+
45
+ ## match tag=apache.access and write to file
46
+ #<match apache.access>
47
+ # type file
48
+ # path /var/log/fluent/access
49
+ #</match>
50
+
51
+ ## match tag=debug.** and dump to console
52
+ <match debug.**>
53
+ type stdout
54
+ </match>
55
+
56
+ # match tag=system.** and forward to another fluent server
57
+ <match system.**>
58
+ type forward
59
+ host 192.168.0.11
60
+ <secondary>
61
+ host 192.168.0.12
62
+ </secondary>
63
+ </match>
64
+
65
+ ## match tag=myapp.** and forward and write to file
66
+ #<match myapp.**>
67
+ # type copy
68
+ # <store>
69
+ # type forward
70
+ # host 192.168.0.13
71
+ # buffer_type file
72
+ # buffer_path /var/log/fluent/myapp-forward
73
+ # retry_limit 50
74
+ # flush_interval 10s
75
+ # </store>
76
+ # <store>
77
+ # type file
78
+ # path /var/log/fluent/myapp
79
+ # </store>
80
+ #</match>
81
+
82
+ ## match fluent's internal events
83
+ #<match fluent.**>
84
+ # type null
85
+ #</match>
86
+
87
+ ## match not matched logs and write to file
88
+ #<match **>
89
+ # type file
90
+ # path /var/log/fluent/else
91
+ # compress gz
92
+ #</match>
93
+
data/fluentd.pid ADDED
@@ -0,0 +1 @@
1
+ 3921
@@ -0,0 +1,5 @@
1
+ module Observed
2
+ class Fluentd
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,30 @@
1
+ require 'observed/fluentd/version'
2
+ require 'observed/reporter'
3
+ require 'observed/reporter/regexp_matching'
4
+ require 'fluent-logger'
5
+
6
+ module Observed
7
+ module Plugins
8
+ class Fluentd < Observed::Reporter
9
+
10
+ include Observed::Reporter::RegexpMatching
11
+
12
+ plugin_name 'fluentd'
13
+
14
+ attribute :tag
15
+ attribute :host
16
+ attribute :port, default: 24224
17
+ attribute :transform, default: ->(data){ data }
18
+
19
+ def report(tag, time, data)
20
+ fluent_logger.post(self.tag, transform.call(data))
21
+ end
22
+
23
+ private
24
+
25
+ def fluent_logger
26
+ @fluent_logger ||= Fluent::Logger::FluentLogger.new(nil, host: host, port: port)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,9 @@
1
+ require 'clockwork'
2
+ require 'observed/clockwork'
3
+
4
+ include Clockwork
5
+ include Observed::Clockwork
6
+
7
+ observed :config_file => 'observed.conf'
8
+
9
+ every(10.seconds, 'myservice')
@@ -0,0 +1,17 @@
1
+ require 'observed/builtin_plugins'
2
+ require 'observed/http'
3
+ require 'observed/fluentd'
4
+
5
+ observe 'myservice', {
6
+ plugin: 'http',
7
+ method: 'get',
8
+ url: 'http://localhost/',
9
+ timeout_in_milliseconds: 3000,
10
+ }
11
+
12
+ match /myservice.*/, {
13
+ plugin: 'fluentd',
14
+ host: 'localhost',
15
+ port: 24224,
16
+ tag: 'debug.myservice'
17
+ }
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'observed/fluentd/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'observed-fluentd'
8
+ spec.version = Observed::Fluentd::VERSION
9
+ spec.authors = ['KUOKA Yusuke']
10
+ spec.email = %w(yusuke.kuoka@gree.net)
11
+ spec.description = %q{Observed Fluentd Output Plugin}
12
+ spec.summary = %q{observed-fluentd is an Observed output plugin for sending observed data to Fluentd}
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = %w(lib)
20
+
21
+ spec.add_dependency 'fluent-logger', '~> 0.4.6'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'rspec'
26
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: observed-fluentd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - KUOKA Yusuke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluent-logger
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.4.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.4.6
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
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Observed Fluentd Output Plugin
70
+ email:
71
+ - yusuke.kuoka@gree.net
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - features/plugin.feature
82
+ - features/support/env.rb
83
+ - fluent.d/fluent.conf
84
+ - fluentd.pid
85
+ - lib/observed/fluentd.rb
86
+ - lib/observed/fluentd/version.rb
87
+ - observe.d/clockwork.rb
88
+ - observe.d/observed.conf
89
+ - observed-fluentd.gemspec
90
+ homepage: ''
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.0.5
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: observed-fluentd is an Observed output plugin for sending observed data to
114
+ Fluentd
115
+ test_files:
116
+ - features/plugin.feature
117
+ - features/support/env.rb