fluent-plugin-munin 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,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-twitter.gemspec
4
+ gemspec
5
+ gem "munin-ruby"
data/Gemfile.lock ADDED
@@ -0,0 +1,31 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fluent-plugin-munin (0.0.1)
5
+ fluentd
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ cool.io (1.1.0)
11
+ iobuffer (>= 1.0.0)
12
+ fluentd (0.10.26)
13
+ cool.io (~> 1.1.0)
14
+ http_parser.rb (~> 0.5.1)
15
+ json (>= 1.4.3)
16
+ msgpack (~> 0.4.4)
17
+ yajl-ruby (~> 1.0)
18
+ http_parser.rb (0.5.3)
19
+ iobuffer (1.1.2)
20
+ json (1.7.5)
21
+ msgpack (0.4.7)
22
+ munin-ruby (0.2.3)
23
+ yajl-ruby (1.1.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ fluent-plugin-munin!
30
+ fluentd
31
+ munin-ruby
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ fluent-plugin-munin
2
+ ===================
3
+
4
+ ## Component
5
+ Fluentd Input plugin. fetch munin-node metrics data with custom intervals.
6
+
7
+ ## Installation
8
+
9
+ ### native gem
10
+
11
+ `````
12
+ gem install fluent-plugin-munin
13
+ `````
14
+
15
+ ### td-agent gem
16
+ `````
17
+ /usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-munin
18
+ `````
19
+
20
+ ## Configuration
21
+
22
+ ### Config Sample
23
+ `````
24
+ <source>
25
+ type munin
26
+ server localhost
27
+ port 4949
28
+ interval 10
29
+ tag_prefix input.munin
30
+ service cpu,df
31
+ record_hostname yes
32
+ </source>
33
+
34
+ <match input.munin.*>
35
+ type stdout
36
+ </match>
37
+ `````
38
+
39
+ ### Output Sample
40
+ `````
41
+ input.munin.cpu: {"hostname":"myhost.example.com","service":"cpu","user":"113183","nice":"340","system":"26584","idle":"74205345","iowait":"26134","irq":"1","softirq":"506","steal":"0","guest":"0"}
42
+ `````
43
+
44
+ ## TODO
45
+ patches welcome!
46
+
47
+ ## Copyright
48
+
49
+ Copyright © 2012- Kentaro Yoshida (@yoshi_ken)
50
+
51
+ ## License
52
+
53
+ Apache License, Version 2.0
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+ Rake::TestTask.new(:test) do |test|
4
+ test.libs << 'lib' << 'test'
5
+ test.pattern = 'test/**/test_*.rb'
6
+ test.verbose = true
7
+ end
8
+
9
+ task :default => :test
10
+
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "fluent-plugin-munin"
6
+ s.version = "0.0.1"
7
+ s.authors = ["Kentaro Yoshida"]
8
+ s.email = ["y.ken.studio@gmail.com"]
9
+ s.homepage = "https://github.com/y-ken/fluent-plugin-munin"
10
+ s.summary = %q{Fluentd Input plugin. fetch munin-node metrics data with custom intervals.}
11
+
12
+ s.files = `git ls-files`.split("\n")
13
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
15
+ s.require_paths = ["lib"]
16
+
17
+ # specify any dependencies here; for example:
18
+ s.add_development_dependency "fluentd"
19
+ s.add_runtime_dependency "fluentd"
20
+ end
@@ -0,0 +1,79 @@
1
+ module Fluent
2
+ class MuninInput < Fluent::Input
3
+ Plugin.register_input('munin', self)
4
+ require 'munin-ruby'
5
+ def initialize
6
+ super
7
+ end
8
+
9
+ config_param :host, :string, :default => 'localhost'
10
+ config_param :port, :integer, :default => 4949
11
+ config_param :interval, :integer, :default => 1
12
+ config_param :tag_prefix, :string
13
+ config_param :service, :string, :default => nil
14
+ config_param :record_hostname, :string, :default => nil
15
+
16
+ def configure(conf)
17
+ super
18
+ service_list = get_service_list
19
+ $log.info "munin-node provides #{service_list.inspect}"
20
+ @services = @service.nil? ? service_list : @service.split(',')
21
+ @record_hostname = @record_hostname || false
22
+ @hostname = `hostname`.chomp
23
+ end
24
+
25
+ def start
26
+ @thread = Thread.new(&method(:run))
27
+ end
28
+
29
+ def shutdown
30
+ disconnect
31
+ @thread.join
32
+ end
33
+
34
+ def run
35
+ loop do
36
+ @services.each do |key|
37
+ tag = "#{@tag_prefix}.#{key}".gsub('__HOSTNAME__', @hostname).gsub('${hostname}', @hostname)
38
+ record = Hash.new
39
+ record.store('hostname', @hostname) if @record_hostname
40
+ record.store('service', key)
41
+ record.merge!(fetch(key).to_hash)
42
+ Engine.emit(tag, Engine.now, record)
43
+ end
44
+ disconnect
45
+ sleep @interval
46
+ end
47
+ end
48
+
49
+ def get_connection
50
+ return Munin::Node.new(@host, @port)
51
+ end
52
+
53
+ def disconnect
54
+ @munin.disconnect
55
+ @munin.connection.close
56
+ end
57
+
58
+ def get_service_list
59
+ @munin ||= get_connection
60
+ begin
61
+ return @munin.list
62
+ rescue Munin::ConnectionError
63
+ @munin = get_connection
64
+ retry
65
+ end
66
+ end
67
+
68
+ def fetch(key)
69
+ @munin ||= get_connection
70
+ begin
71
+ values = @munin.fetch(key)
72
+ return values[key]
73
+ rescue Munin::ConnectionError
74
+ @munin = get_connection
75
+ retry
76
+ end
77
+ end
78
+ end
79
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,28 @@
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
+
12
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
14
+ require 'fluent/test'
15
+ unless ENV.has_key?('VERBOSE')
16
+ nulllogger = Object.new
17
+ nulllogger.instance_eval {|obj|
18
+ def method_missing(method, *args)
19
+ # pass
20
+ end
21
+ }
22
+ $log = nulllogger
23
+ end
24
+
25
+ require 'fluent/plugin/in_munin'
26
+
27
+ class Test::Unit::TestCase
28
+ end
@@ -0,0 +1,39 @@
1
+ require 'helper'
2
+
3
+ class MuninInputTest < Test::Unit::TestCase
4
+ def setup
5
+ Fluent::Test.setup
6
+ end
7
+
8
+ CONFIG = %[
9
+ host localhost
10
+ port 4949
11
+ interval 30
12
+ tag_prefix input.munin
13
+ record_hostname yes
14
+ ]
15
+
16
+ def create_driver(conf=CONFIG,tag='test')
17
+ Fluent::Test::OutputTestDriver.new(Fluent::MuninInput, tag).configure(conf)
18
+ end
19
+
20
+ def test_configure
21
+ assert_raise(Fluent::ConfigError) {
22
+ d = create_driver('')
23
+ }
24
+ d = create_driver %[
25
+ host localhost
26
+ port 4949
27
+ interval 30
28
+ tag_prefix input.munin
29
+ record_hostname yes
30
+ ]
31
+ d.instance.inspect
32
+ assert_equal 'localhost', d.instance.host
33
+ assert_equal 4949, d.instance.port
34
+ assert_equal 30, d.instance.interval
35
+ assert_equal 'input.munin', d.instance.tag_prefix
36
+ assert_equal 'yes', d.instance.record_hostname
37
+ end
38
+ end
39
+
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-munin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kentaro Yoshida
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: fluentd
16
+ requirement: &21592420 !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: *21592420
25
+ - !ruby/object:Gem::Dependency
26
+ name: fluentd
27
+ requirement: &21591140 !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: *21591140
36
+ description:
37
+ email:
38
+ - y.ken.studio@gmail.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - Gemfile.lock
46
+ - README.md
47
+ - Rakefile
48
+ - fluent-plugin-munin.gemspec
49
+ - lib/fluent/plugin/in_munin.rb
50
+ - test/helper.rb
51
+ - test/plugin/test_in_munin.rb
52
+ homepage: https://github.com/y-ken/fluent-plugin-munin
53
+ licenses: []
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 1.8.11
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: Fluentd Input plugin. fetch munin-node metrics data with custom intervals.
76
+ test_files:
77
+ - test/helper.rb
78
+ - test/plugin/test_in_munin.rb