fluent-plugin-sar 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c2f1de19c13358cdfb0040af85545cb253a7f062
4
+ data.tar.gz: b61888ae08152566a0c0059c61d9396e1cfe0116
5
+ SHA512:
6
+ metadata.gz: e5c5e049083875ddc3098b3ecf831c32390a263841fade7c435886cbb12fe99a403570fa8f474ecfa1dcec516e5a1f090b5d9638c1b9dec4f025228d40b11278
7
+ data.tar.gz: 9e49bc41ed286fbb6e56ba7931f4c08ea0306e81cb0493e00c62ee52fa5eee8fd64b50e49ece22eae5abfc9b3d988406dee240997c3fa665536dda2be28e32eb
@@ -0,0 +1,18 @@
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
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 hirotaka tajiri
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,112 @@
1
+ # Fluent::Plugin::Sar
2
+
3
+ Fluentd input plugin to get sar result.
4
+
5
+ This plugin needs "sysstat".
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'fluent-plugin-sar'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install fluent-plugin-sar
20
+
21
+ ## Overview
22
+
23
+ This plugin collect "sar command result" every (interval) minutes.
24
+
25
+ ## Configuration
26
+ ### Parameters:
27
+
28
+ + sar_option
29
+
30
+
31
+ (required)
32
+
33
+ same sar option, but not all.
34
+
35
+ e.g.) sysstat version 9.0.4 on CentOS 6.5
36
+
37
+ Support
38
+
39
+ b Report I/O and transfer rate statistics.
40
+ B Report paging statistics. Some of the metrics below are available only with post 2.5 kernels.
41
+ m Report power management statistics. Note that these statistics depend on sadc option "-S POWER" to be collected.
42
+ q Report queue length and load averages.
43
+ r Report memory utilization statistics.
44
+ R Report memory statistics.
45
+ S Report swap space utilization statistics.
46
+ u Report CPU utilization.
47
+ v Report status of inode, file and other kernel tables.
48
+ w Report task creation and system switching activity.
49
+ W Report swapping statistics.
50
+
51
+ Not support
52
+
53
+ A
54
+ C
55
+ d
56
+ I
57
+ j
58
+ n
59
+ P
60
+ p
61
+ y
62
+
63
+ - tag
64
+
65
+
66
+ (optional | default : "sar_result.tag")
67
+
68
+ - interval
69
+
70
+
71
+ (optional | defalut : 5)
72
+
73
+ every (interval) minutes.
74
+
75
+ - hostname_output
76
+
77
+
78
+ (optional | defalut : True)
79
+
80
+ true or false
81
+
82
+ - hostname
83
+
84
+
85
+ (optionl | defalut : your server's hostname)
86
+
87
+ ### Example:
88
+
89
+ <source>
90
+ type sar
91
+ sar_option u q
92
+ tag sar.tag
93
+ interval 10
94
+ hostname_output true
95
+ hostname check_host01
96
+ </source>
97
+
98
+ output
99
+
100
+ sar.tag: {"hostname":"check_host01","check_time":"18:51:25","runq-sz":"0","plist-sz":"223","ldavg-1":"0.00","ldavg-5":"0.00","ldavg-15":"0.00","CPU":"all","%user":"0.00","%nice":"0.00","%system":"1.03","%iowait":"0.00","%steal":"0.00","%idle":"98.97"}
101
+
102
+ ## Contributing
103
+
104
+ 1. Fork it
105
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
106
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
107
+ 4. Push to the branch (`git push origin my-new-feature`)
108
+ 5. Create new Pull Request
109
+
110
+ ## Copyright
111
+
112
+ Copyright (c) 2014 Hirotaka Tajiri. See [LICENSE](LICENSE.txt) for details.
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rspec/core'
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec) {| spec |
7
+ spec.pattern = FileList['spec/*_spec.rb']
8
+ }
9
+ task :default => :spec
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ #lib = File.expand_path('../lib', __FILE__)
3
+ #$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ $:.push File.expand_path('../lib', __FILE__)
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fluent-plugin-sar"
8
+ spec.version = "0.0.2"
9
+ spec.authors = ["Hirotaka Tajiri"]
10
+ spec.email = ["ganryu_koziro@excite.co.jp"]
11
+ spec.homepage = "https://github.com/hirotaka-tajiri/fluent-plugin-sar"
12
+ spec.description = %q{Fluentd input plugin to get sar result}
13
+ spec.summary = %q{Fluentd input plugin to get sar result}
14
+ spec.license = "MIT"
15
+ spec.has_rdoc = false
16
+
17
+ spec.files = `git ls-files`.split("\n")
18
+ spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ spec.executables = `git ls-files -- bin/*`.split("\n").map{| f | File.basename(f)}
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'fluentd', "~> 0.10"
23
+ spec.add_development_dependency "rake", ">0"
24
+ spec.add_development_dependency "rspec", ">0"
25
+ end
@@ -0,0 +1,60 @@
1
+ class SarInput < Fluent::Input
2
+ Fluent::Plugin.register_input('sar', self)
3
+
4
+ config_param :sar_option, :string, default: ''
5
+ config_param :tag, :string, default: 'sar_result.tag'
6
+ config_param :interval, :integer, default: 5
7
+ config_param :hostname_output, :bool, default: true
8
+ config_param :hostname, :string, default: Socket.gethostname
9
+
10
+ def configure(conf)
11
+ super
12
+ @interval_m = @sar_option.split.size.zero? ? @interval * 60 : @interval * 60 - 1
13
+ begin
14
+ `sar -V`
15
+ raise Fluent::ConfigError, "sar_option contains illegal characters.(sar_option: #{@sar_option})" if /[^a-zA-Z ]+/ =~ @sar_option
16
+ rescue
17
+ raise Fluent::ConfigError, "sar(sysstat) is not installed."
18
+ end
19
+ end
20
+
21
+ def start
22
+ super
23
+ @thread = Thread.new(&method(:run))
24
+ end
25
+
26
+ def shutdown
27
+ @thread.kill
28
+ end
29
+
30
+ private
31
+
32
+ def run
33
+ loop do
34
+ @result = Hash.new
35
+ @result["hostname"] = @hostname if @hostname_output
36
+ Fluent::Engine.emit(@tag, Fluent::Engine.now, @result.merge(sar_execute(@sar_option.split)))
37
+ sleep @interval_m
38
+ end
39
+ end
40
+
41
+ def sar_execute(opt_ary)
42
+
43
+ rlt = Hash.new{| k, v | Hash[k] = Hash.new }
44
+ rec = Hash.new
45
+ th = Array.new
46
+
47
+ opt_ary.each {| opt |
48
+ th << Thread.new {
49
+ i = 0
50
+ `LANG=C sar -#{opt} 1 1 | grep -vi average | tail -n2`.split("\n").each{| a | rlt[(i += 1)] = a.split }
51
+ rlt[1][0].sub!(/[0-9]{2}\:[0-9]{2}\:[0-9]{2}/, "check_time")
52
+ rec.merge!(Hash[*rlt[1].zip(rlt[2]).flatten])
53
+ }
54
+ }
55
+ th.each {| t | t.join }
56
+
57
+ rec
58
+ end
59
+ end
60
+
@@ -0,0 +1,68 @@
1
+ # encoding: UTF-8
2
+ require_relative 'spec_helper'
3
+ describe "SarInput" do
4
+
5
+ before { Fluent::Test.setup }
6
+
7
+ CONFIG = %[
8
+ type sar
9
+ sar_option u q r b w B R S v W
10
+ tag sar.tag
11
+ interval 10
12
+ hostname_output false
13
+ hostname test_node
14
+ ]
15
+ CONF_D = %[
16
+ type sar
17
+ sar_option u
18
+ ]
19
+ CNF_I1 = %[
20
+ type sar
21
+ sar_command_path /usr/bin/sar
22
+ sar_option |
23
+ ]
24
+ CNF_I2 = %[
25
+ type sar
26
+ sar_command_path /usr/bin/sar
27
+ sar_option |;
28
+ ]
29
+ CNF_I3 = %[
30
+ type sar
31
+ sar_command_path /usr/bin/sar
32
+ sar_option a ;rm b
33
+ ]
34
+
35
+ def create_driver(conf)
36
+ Fluent::Test::InputTestDriver.new(SarInput).configure(conf)
37
+ end
38
+
39
+ describe "config test" do
40
+
41
+ let(:driver) { Fluent::Test::InputTestDriver.new(SarInput).configure(CONFIG) }
42
+ let(:driver1) { Fluent::Test::InputTestDriver.new(SarInput).configure(CONF_D) }
43
+
44
+ context "Test config F " do
45
+ subject { driver.instance }
46
+ its (:sar_option) { should eq "u q r b w B R S v W" }
47
+ its (:tag) { should eq "sar.tag" }
48
+ its (:interval) { should eq 10 }
49
+ its (:hostname_output) { should eq false }
50
+ its (:hostname) { should eq "test_node"}
51
+ end
52
+
53
+ context "Test config defalut " do
54
+ subject { driver1.instance }
55
+ its (:sar_option) { should eq 'u' }
56
+ its (:tag) { should eq 'sar_result.tag' }
57
+ its (:interval) { should eq 5 }
58
+ its (:hostname_output) { should eq true }
59
+ its (:hostname) { should eq Socket.gethostname}
60
+ end
61
+
62
+ context "Test config raise error" do
63
+ it { expect(lambda{create_driver(CNF_I1)}).to raise_error(Fluent::ConfigError) }
64
+ it { expect(lambda{create_driver(CNF_I2)}).to raise_error(Fluent::ConfigError) }
65
+ it { expect(lambda{create_driver(CNF_I3)}).to raise_error(Fluent::ConfigError) }
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,8 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ require 'bundler'
4
+
5
+ require 'rspec'
6
+ require 'fluent/test'
7
+
8
+ Dir["./lib/**/*.rb"].each{| f | require f}
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-sar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Hirotaka Tajiri
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.10'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.10'
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
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
+ description: Fluentd input plugin to get sar result
56
+ email:
57
+ - ganryu_koziro@excite.co.jp
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - fluent-plugin-sar.gemspec
68
+ - lib/fluent/plugin/in_sar.rb
69
+ - spec/in_sar_spec.rb
70
+ - spec/spec_helper.rb
71
+ homepage: https://github.com/hirotaka-tajiri/fluent-plugin-sar
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.2.1
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Fluentd input plugin to get sar result
95
+ test_files:
96
+ - spec/in_sar_spec.rb
97
+ - spec/spec_helper.rb