Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
setup a simple api for defining munin plugins in a friendly way
- Loading branch information
1 parent
b716a89
commit 99997db
Showing
5 changed files
with
91 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.