fluent-exec 0.0.1

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-exec.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Takenari Shinohara
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,32 @@
1
+ # Fluent-Exec
2
+
3
+ Log command's exit status, output and runtime to fluentd.
4
+
5
+ ## Installation
6
+
7
+ Install fluent-exec as a gem:
8
+
9
+ $ gem install fluent-exec
10
+
11
+ ## Usage
12
+
13
+ $ fluent-exec echo.test echo 'testing...'
14
+ testing...
15
+
16
+ will log this record with tag `echo.test`:
17
+
18
+ {
19
+ "command": ["echo", "testing..."],
20
+ "exitstatus": 0,
21
+ "stdout": "testing...\n",
22
+ "stderr": "",
23
+ "runtime": 0.004784
24
+ }
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/fluent-exec ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "pathname"
4
+ bin_file = Pathname.new(__FILE__).realpath
5
+ $:.unshift File.expand_path("../../lib", bin_file)
6
+
7
+ require 'fluent-exec'
8
+ Fluent::Exec::CLI.new.run ARGV
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fluent-exec/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "fluent-exec"
8
+ gem.version = Fluent::Exec::VERSION
9
+ gem.authors = ["Takenari Shinohara"]
10
+ gem.email = ["takenari.shinohara@gmail.com"]
11
+ gem.description = "Log command's exit status, output and runtime to fluentd."
12
+ gem.summary = "Log command's exit status, output and runtime to fluentd."
13
+ gem.homepage = "https://github.com/tshinohara/fluent-exec"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'fluent-logger', '~>0.4.3'
21
+ end
@@ -0,0 +1,66 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "fluent-exec/version"
3
+ require "fluent-logger"
4
+ require "open3"
5
+
6
+ module Fluent
7
+ module Exec
8
+ class CLI
9
+ HOST = 'localhost'
10
+ PORT = 24224
11
+
12
+ def run(args)
13
+ tag = args.shift
14
+ cmd = args
15
+ env = {}
16
+ in_str = ''
17
+ out_str = ''
18
+ err_str = ''
19
+
20
+ begin_time = Time.now
21
+ sin, sout, serr, thr = Open3.popen3(env, *cmd)
22
+
23
+ sin_t = Thread.new do
24
+ sin.write s while s = $stdin.read(1024)
25
+ sin.close
26
+ end
27
+
28
+ sout_t = Thread.new do
29
+ while s = sout.read(1024)
30
+ out_str << s
31
+ $stdout.write s
32
+ end
33
+ end
34
+
35
+ serr_t = Thread.new do
36
+ while s = serr.read(1024)
37
+ err_str << s
38
+ $stderr.write s
39
+ end
40
+ end
41
+
42
+ status = thr.value
43
+ end_time = Time.now
44
+ #sin_t.join
45
+ sout_t.join
46
+ serr_t.join
47
+ es = status.exitstatus
48
+ #コマンドの実行を優先?
49
+ #fluentdサーバに接続できない場合はどうする?
50
+ # failover (file|stdout)?
51
+ begin
52
+ log = Fluent::Logger::FluentLogger.new(nil, :host => HOST, :port => PORT)
53
+ log.post tag, {
54
+ :command => ARGV,
55
+ :exitstatus => es,
56
+ :stdout => out_str,
57
+ :stderr => err_str,
58
+ :runtime => end_time - begin_time,
59
+ }
60
+ rescue => ex
61
+ end
62
+ exit es
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,5 @@
1
+ module Fluent
2
+ module Exec
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-exec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Takenari Shinohara
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: fluent-logger
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.4.3
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.4.3
30
+ description: Log command's exit status, output and runtime to fluentd.
31
+ email:
32
+ - takenari.shinohara@gmail.com
33
+ executables:
34
+ - fluent-exec
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - bin/fluent-exec
44
+ - fluent-exec.gemspec
45
+ - lib/fluent-exec.rb
46
+ - lib/fluent-exec/version.rb
47
+ homepage: https://github.com/tshinohara/fluent-exec
48
+ licenses: []
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 1.8.23
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Log command's exit status, output and runtime to fluentd.
71
+ test_files: []
72
+ has_rdoc: