munin_plugin 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 James Golick
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,29 @@
1
+ = Munin Plugin
2
+
3
+ A friendly API for creating munin plugins in ruby.
4
+
5
+ Here's the example from the munin site, implmeneted with munin_plugin:
6
+
7
+ #!/usr/bin/env ruby -rubygems
8
+
9
+ require 'munin_plugin'
10
+
11
+ munin_plugin do
12
+ graph_title "Load average"
13
+ graph_vlabel "load"
14
+ load.label "load"
15
+
16
+ collect do
17
+ load.value `cat /proc/loadavg`.split(" ")[1]
18
+ end
19
+ end
20
+
21
+ That's it.
22
+
23
+ = Install
24
+
25
+ sudo gem install munin_plugin
26
+
27
+ == Copyright
28
+
29
+ Copyright (c) 2010 James Golick. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "munin_plugin"
8
+ gem.summary = %Q{Friendly API for creating munin plugins in ruby.}
9
+ gem.description = %Q{Friendly API for creating munin plugins in ruby.}
10
+ gem.email = "jamesgolick@gmail.com"
11
+ gem.homepage = "http://github.com/jamesgolick/munin_plugin"
12
+ gem.authors = ["James Golick"]
13
+ end
14
+ Jeweler::GemcutterTasks.new
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
17
+ end
18
+
19
+ require 'rake/testtask'
20
+ Rake::TestTask.new(:test) do |test|
21
+ test.libs << 'lib' << 'test'
22
+ test.pattern = 'test/**/test_*.rb'
23
+ test.verbose = true
24
+ end
25
+
26
+ begin
27
+ require 'rcov/rcovtask'
28
+ Rcov::RcovTask.new do |test|
29
+ test.libs << 'test'
30
+ test.pattern = 'test/**/test_*.rb'
31
+ test.verbose = true
32
+ end
33
+ rescue LoadError
34
+ task :rcov do
35
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
36
+ end
37
+ end
38
+
39
+ task :test => :check_dependencies
40
+
41
+ task :default => :test
42
+
43
+ require 'rake/rdoctask'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "fetlife-munin-plugins #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/examples/loadavg ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby -rubygems
2
+
3
+ require 'munin_plugin'
4
+
5
+ munin_plugin do
6
+ graph_title "Load average"
7
+ graph_vlabel "load"
8
+ load.label "load"
9
+
10
+ collect do
11
+ load.value `cat /proc/loadavg`.split(" ")[1]
12
+ end
13
+ end
14
+
@@ -0,0 +1,77 @@
1
+ class MuninPlugin
2
+ class Attribute
3
+ attr_reader :name, :args
4
+
5
+ def initialize(*args)
6
+ if args.first.is_a?(Attribute)
7
+ @name = [args.shift.name, args.shift].join(".")
8
+ else
9
+ @name = args.first
10
+ end
11
+
12
+ @args = args
13
+ end
14
+
15
+ def method_missing(method, *args, &block)
16
+ @name = [name, method].join(".")
17
+ @args = args
18
+ self
19
+ end
20
+
21
+ def to_s
22
+ [name, *args].uniq.join(' ')
23
+ end
24
+ end
25
+
26
+ class Collector
27
+ undef_method :load
28
+
29
+ def initialize(&block)
30
+ instance_eval(&block)
31
+ end
32
+
33
+ def proxy_attributes
34
+ @proxy_attributes ||= []
35
+ end
36
+
37
+ def method_missing(method, *args, &block)
38
+ item = Attribute.new(method, *args, &block)
39
+ proxy_attributes << item
40
+ item
41
+ end
42
+
43
+ def collect(&block)
44
+ if block_given?
45
+ @collect = block
46
+ end
47
+ @collect
48
+ end
49
+
50
+ def to_s
51
+ proxy_attributes.map { |c| c.to_s }.join("\n") + "\n"
52
+ end
53
+ end
54
+
55
+ attr_reader :config
56
+
57
+ def initialize(&block)
58
+ @config = Collector.new(&block)
59
+ end
60
+
61
+ def display_config
62
+ print config
63
+ end
64
+
65
+ def display_value
66
+ print Collector.new(&config.collect)
67
+ end
68
+
69
+ def run
70
+ ARGV.first == "config" ? display_config : display_value
71
+ end
72
+ end
73
+
74
+ # yeah, yeah :-)
75
+ def munin_plugin(&block)
76
+ MuninPlugin.new(&block).run
77
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: munin_plugin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Golick
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-04 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Friendly API for creating munin plugins in ruby.
17
+ email: jamesgolick@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - VERSION
32
+ - examples/loadavg
33
+ - lib/munin_plugin.rb
34
+ has_rdoc: true
35
+ homepage: http://github.com/jamesgolick/munin_plugin
36
+ licenses: []
37
+
38
+ post_install_message:
39
+ rdoc_options:
40
+ - --charset=UTF-8
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.3.5
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: Friendly API for creating munin plugins in ruby.
62
+ test_files: []
63
+