Skip to content

Commit

Permalink
setup a simple api for defining munin plugins in a friendly way
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgolick committed Jan 5, 2010
1 parent b716a89 commit 99997db
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 17 deletions.
14 changes: 14 additions & 0 deletions examples/loadavg
@@ -0,0 +1,14 @@
#!/usr/bin/env ruby

require 'munin_plugin'

munin_plugin do
graph_title "Load average"
graph_vlabel "load"
load.label "load"

collect do
load.value `cat /proc/loadavg`.split(" ")[1]
end
end

Empty file removed lib/fetlife-munin-plugins.rb
Empty file.
77 changes: 77 additions & 0 deletions lib/munin_plugin.rb
@@ -0,0 +1,77 @@
class MuninPlugin
class Attribute
attr_reader :name, :args

def initialize(*args)
if args.first.is_a?(Attribute)
@name = [args.shift.name, args.shift].join(".")
else
@name = args.first
end

@args = args
end

def method_missing(method, *args, &block)
@name = [name, method].join(".")
@args = args
self
end

def to_s
[name, *args].uniq.join(' ')
end
end

class Collector
undef_method :load

def initialize(&block)
instance_eval(&block)
end

def proxy_attributes
@proxy_attributes ||= []
end

def method_missing(method, *args, &block)
item = Attribute.new(method, *args, &block)
proxy_attributes << item
item
end

def collect(&block)
if block_given?
@collect = block
end
@collect
end

def to_s
proxy_attributes.map { |c| c.to_s }.join("\n") + "\n"
end
end

attr_reader :config

def initialize(&block)
@config = Collector.new(&block)
end

def display_config
print config
end

def display_value
print Collector.new(&config.collect)
end

def run
ARGV.first == "config" ? display_config : display_value
end
end

# yeah, yeah :-)
def munin_plugin(&block)
MuninPlugin.new(&block).run
end
10 changes: 0 additions & 10 deletions test/helper.rb

This file was deleted.

7 changes: 0 additions & 7 deletions test/test_fetlife-munin-plugins.rb

This file was deleted.

0 comments on commit 99997db

Please sign in to comment.