class MuninGraph
This class allows the transformation between graphite and munin config. It constructs an AST parsing the munin config information and outputs a valid graphic in graphite url format Jose Fernandez 2011
Constants
- TOKENS
This array of hashes will be used to match what kind of line we are dealing with and to know the corresponding ast node class
Attributes
root[R]
Public Class Methods
graph_for(config)
click to toggle source
# File lib/munin_graph.rb, line 30 def self.graph_for(config) MuninGraph.new(config) end
new(config)
click to toggle source
# File lib/munin_graph.rb, line 34 def initialize(config) @raw_config = config parse_config end
Public Instance Methods
config=(config)
click to toggle source
# File lib/munin_graph.rb, line 39 def config=(config) @config = config self.root.config = config end
parse_config()
click to toggle source
# File lib/munin_graph.rb, line 109 def parse_config @root = ASTNode.new("") @root.parent = nil current_node = @root @raw_config.each_line do |line| # For every line of config we match against every token TOKENS.each do |token| if line =~ token[:matcher] # When we find a match... if token[:klass].new("").is_a? FieldPropertyNode # In Property field we have to set it to a FieldDeclarationNode (an artificial node grouping those fields) if !current_node.is_a? FieldDeclarationNode # A new FieldDeclaration has to ve created node = FieldDeclarationNode.new("") node.properties[:field_name] = $1 current_node.add_child node current_node = node elsif current_node.properties[:field_name] != $1 if (aux = @root.children_of_class(FieldDeclarationNode).find { |i| i.properties[:field_name] == $1 } ) current_node = aux else # We use the one declared before (note that different metrics could not be interlaced) node = FieldDeclarationNode.new("") node.properties[:field_name] = $1 current_node.parent.add_child node current_node = node end end current_node.add_child token[:klass].send("new",line) else @root.add_child token[:klass].send("new",line) end break end end end end
to_gdash()
click to toggle source
# File lib/munin_graph.rb, line 60 def to_gdash self.root.compile self.root.to_gdash end
to_graphite()
click to toggle source
# File lib/munin_graph.rb, line 44 def to_graphite graph = Graphite::MyGraph.new self.root.compile graph.url = self.root.url self.root.properties[:category] ||= "other" if @config["graphite_prefix"] == "" || !@config["graphite_prefix"] && @config["graphite_graph_prefix"] && @config["graphite_graph_prefix"] != "" puts "DEPRECATION WARNING: parameter graphite_graph_prefix is not used anymore, please use graphite_prefix instead." @config["graphite_prefix"] = @config["graphite_graph_prefix"] end graph.name = "#{@config["hostname"]}.#{self.root.properties["category"]}.#{self.root.properties["metric"]}" graph.name = "#{@config["graphite_prefix"]}.#{graph.name}" if @config["graphite_prefix"] && @config["graphite_prefix"] != "" return graph end