fluent-plugin-munin-node 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e19be264a0d1f562630effd9d72e4eb4967afe7f
4
+ data.tar.gz: 2117c050f0b25c8e3ec7d2954c0be0ee1bf728a5
5
+ SHA512:
6
+ metadata.gz: 6c92e3b576df6398dc890bc45a6415ddec47cba1615d7f489b86f5745d4803995ea9a3866870557f324977c62d439f2db33e38fd6afd90bbdb97de6b8d747e47
7
+ data.tar.gz: 2adaad102c12490a78b62aef93729a804721e98bc1ce25cb354beaf61c52bdecd6802947f9e99bb6494465c241309bb2150757c4d3ddc320d587d1411f80652f
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ test.rb
11
+ fluent.conf
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --require spec_helper
2
+ --colour
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1
5
+ - 2.2
6
+ script:
7
+ - bundle install
8
+ - bundle exec rake
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-munin-node.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Genki Sugawara
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # fluent-plugin-munin-node
2
+
3
+ Fluentd input plugin for Munin node.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'fluent-plugin-munin-node'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install fluent-plugin-munin-node
20
+
21
+ ## Configuration
22
+
23
+ ```apache
24
+ <source>
25
+ type munin_node
26
+
27
+ #node_host 127.0.0.1
28
+ #node_port 10050
29
+ #interval 60
30
+ #tag munin.item
31
+ #plugin_key plugin
32
+ #datasource_key datasource
33
+ #item_value_key value
34
+ #extra {}
35
+ #bulk false
36
+ </source>
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ ### Get munin datasources as multiple records
42
+
43
+ ```apache
44
+ <source>
45
+ type munin_node
46
+ extra {"hostname", "my-host"}
47
+ </source>
48
+ ```
49
+
50
+ ```
51
+ 2015-91-02 12:30:09 +0000 munin.item: {"plugin":"cpu","datasource":"user","value":"4192","hostname":"my-host"}
52
+ 2015-91-02 12:30:09 +0000 munin.item: {"plugin":"cpu","datasource":"nice","value":"0","hostname":"my-host"}
53
+ 2015-91-02 12:30:09 +0000 munin.item: {"plugin":"cpu","datasource":"system","value":"1935","hostname":"my-host"}
54
+ ```
55
+
56
+ ## Get munin datasources as a single record
57
+
58
+ ```apache
59
+ <source>
60
+ type munin_node
61
+ extra {"hostname", "my-host"}
62
+ bulk true
63
+ </source>
64
+ ```
65
+
66
+ ```
67
+ 2015-01-02 12:30:40 +0000 munin.item: {"cpu":{"user":"4112","nice":"0","system":"1894",...,"hostname":"my-host"}
68
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fluent/plugin/munin/node"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fluent_plugin_munin_node/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'fluent-plugin-munin-node'
8
+ spec.version = FluentPluginMuninNode::VERSION
9
+ spec.authors = ['Genki Sugawara']
10
+ spec.email = ['sugawara@cookpad.com']
11
+
12
+ spec.summary = %q{Fluentd input plugin for Munin node.}
13
+ spec.description = %q{Fluentd input plugin for Munin node.}
14
+ spec.homepage = 'https://github.com/winebarrel/fluent-plugin-munin-node'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'fluentd'
23
+ spec.add_dependency 'munin-ruby', '>= 0.1.4'
24
+ spec.add_development_dependency 'bundler'
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'rspec', '>= 3.0.0'
27
+ spec.add_development_dependency 'test-unit', '>= 3.1.0'
28
+ spec.add_development_dependency 'timecop'
29
+ end
@@ -0,0 +1,113 @@
1
+ require 'fluent_plugin_munin_node/version'
2
+
3
+ class Fluent::MuninNodeInput < Fluent::Input
4
+ Fluent::Plugin.register_input('munin_node', self)
5
+
6
+ unless method_defined?(:log)
7
+ define_method('log') { $log }
8
+ end
9
+
10
+ unless method_defined?(:router)
11
+ define_method('router') { Fluent::Engine }
12
+ end
13
+
14
+ config_param :node_host, :string, :default => '127.0.0.1'
15
+ config_param :node_port, :integer, :default => 4949
16
+ config_param :interval, :time, :default => 60
17
+ config_param :tag, :string, :default => 'munin.item'
18
+ config_param :plugin_key, :string, :default => 'plugin'
19
+ config_param :datasource_key, :string, :default => 'datasource'
20
+ config_param :datasource_value_key, :string, :default => 'value'
21
+ config_param :extra, :hash, :default => {}
22
+ config_param :bulk, :bool, :default => false
23
+
24
+ def initialize
25
+ super
26
+ require 'munin-ruby'
27
+ end
28
+
29
+ def configure(conf)
30
+ super
31
+ end
32
+
33
+ def start
34
+ super
35
+
36
+ @node = Munin::Node.new(@node_host, @node_port)
37
+ @loop = Coolio::Loop.new
38
+ timer = TimerWatcher.new(@interval, true, log, &method(:fetch_items))
39
+ @loop.attach(timer)
40
+ @thread = Thread.new(&method(:run))
41
+ end
42
+
43
+ def shutdown
44
+ @loop.watchers.each(&:detach)
45
+ @loop.stop
46
+
47
+ # XXX: Comment out for exit soon. Is it OK?
48
+ #@thread.join
49
+
50
+ @node.disconnect
51
+ @node.connection.close
52
+ end
53
+
54
+ private
55
+
56
+ def run
57
+ @loop.run
58
+ rescue => e
59
+ log.error(e.message)
60
+ log.error_backtrace(e.backtrace)
61
+ end
62
+
63
+ def fetch_items
64
+ values_by_plugin = {}
65
+
66
+ @node.list.each do |plugin|
67
+ begin
68
+ plugin_values = @node.fetch(plugin)
69
+ values_by_plugin.update(plugin_values)
70
+ rescue => e
71
+ log.warn("#{plugin}: #{e.message}")
72
+ log.warn_backtrace(e.backtrace)
73
+ end
74
+ end
75
+
76
+ emit_items(values_by_plugin)
77
+ end
78
+
79
+ def emit_items(values_by_plugin)
80
+ time = Time.now
81
+
82
+ if @bulk
83
+ router.emit(@tag, time.to_i, values_by_plugin.merge(extra))
84
+ else
85
+ values_by_plugin.each do |plugin, value_by_datasource|
86
+ value_by_datasource.each do |datasource, value|
87
+ record = {
88
+ @plugin_key => plugin,
89
+ @datasource_key => datasource,
90
+ @datasource_value_key => value,
91
+ }
92
+
93
+ router.emit(@tag, time.to_i, record.merge(extra))
94
+ end
95
+ end
96
+ end
97
+ end
98
+
99
+ class TimerWatcher < Coolio::TimerWatcher
100
+ def initialize(interval, repeat, log, &callback)
101
+ @callback = callback
102
+ @log = log
103
+ super(interval, repeat)
104
+ end
105
+
106
+ def on_timer
107
+ @callback.call
108
+ rescue => e
109
+ @log.error(e.message)
110
+ @log.error_backtrace(e.backtrace)
111
+ end
112
+ end # TimerWatcher
113
+ end # Fluent::MuninNodeInput
@@ -0,0 +1,3 @@
1
+ module FluentPluginMuninNode
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-munin-node
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Genki Sugawara
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-13 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'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: munin-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
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: rake
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
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: test-unit
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: 3.1.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: 3.1.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: timecop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Fluentd input plugin for Munin node.
112
+ email:
113
+ - sugawara@cookpad.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - .rspec
120
+ - .travis.yml
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - bin/console
126
+ - bin/setup
127
+ - fluent-plugin-munin-node.gemspec
128
+ - lib/fluent/plugin/in_munin_node.rb
129
+ - lib/fluent_plugin_munin_node/version.rb
130
+ homepage: https://github.com/winebarrel/fluent-plugin-munin-node
131
+ licenses:
132
+ - MIT
133
+ metadata: {}
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 2.0.14
151
+ signing_key:
152
+ specification_version: 4
153
+ summary: Fluentd input plugin for Munin node.
154
+ test_files: []