Parent

Visage::Profile

Attributes

errors[R]
hosts[R]
metrics[R]
name[R]
options[R]
percentiles[R]
selected_hosts[R]
selected_metrics[R]
selected_percentiles[R]

Public Class Methods

all(opts={}) click to toggle source
# File lib/visage-app/profile.rb, line 34
def self.all(opts={})
  sort = opts[:sort]
  profiles = self.load
  profiles = ((sort == "name") or not sort) ? profiles.sort_by {|k,v| v[:profile_name]}.map {|i| i.last } : profiles.values
  # FIXME - to sort by creation time we need to save creation time on each profile
  profiles.map { |prof| self.new(prof) }
end
get(id) click to toggle source
# File lib/visage-app/profile.rb, line 28
def self.get(id)
  url = id.downcase.gsub(/[^\w]+/, "+")
  profiles = self.load
  profiles[url] ? self.new(profiles[url]) : nil
end
load() click to toggle source
# File lib/visage-app/profile.rb, line 24
def self.load
  Visage::Config::File.load('profiles.yaml', :create => true, :ignore_bundled => true) || {}
end
new(opts={}) click to toggle source
# File lib/visage-app/profile.rb, line 42
def initialize(opts={})
  @options = opts
  @options[:url] = @options[:profile_name] ? @options[:profile_name].downcase.gsub(/[^\w]+/, "+") : nil
  @errors = {}
  @options[:hosts]       = @options[:hosts].values       if @options[:hosts].class       == Hash
  @options[:metrics]     = @options[:metrics].values     if @options[:metrics].class     == Hash
  @options[:percentiles] = @options[:percentiles].values if @options[:percentiles].class == Hash
end
old_format?() click to toggle source
# File lib/visage-app/profile.rb, line 15
def self.old_format?
  profiles = Visage::Config::File.load('profiles.yaml', :create => true, :ignore_bundled => true) || {}
  profiles.each_pair do |name, attrs|
    return true if attrs[:hosts] =~ /\*/ || attrs[:metrics] =~ /\*/
  end

  false
end

Public Instance Methods

graphs() click to toggle source
# File lib/visage-app/profile.rb, line 84
def graphs
  graphs      = []
  hosts       = @options[:hosts]
  metrics     = @options[:metrics]
  percentiles = @options[:percentiles]

  hosts.each do |host|
    attrs = {}
    globs = Visage::Collectd::RRDs.metrics(:host => host, :metrics => metrics)
    globs.each do |n|
      parts    = n.split('/')
      plugin   = parts[0]
      instance = parts[1]
      attrs[plugin] ||= []
      attrs[plugin] << instance
    end

    attrs.each_pair do |plugin, instances|
      graphs << Visage::Graph.new(:host => host,
                                  :plugin => plugin,
                                  :instances => instances,
                                  :percentiles => percentiles)
    end
  end

  graphs
end
method_missing(method) click to toggle source

Hashed based access to @options.

# File lib/visage-app/profile.rb, line 52
def method_missing(method)
  @options[method]
end
private_id() click to toggle source
# File lib/visage-app/profile.rb, line 112
def private_id
  Digest::MD5.hexdigest("#{@options[:url]}\n")
end
save() click to toggle source
# File lib/visage-app/profile.rb, line 56
def save
  if valid?
    # Construct record.
    attrs = { :hosts        => @options[:hosts],
              :metrics      => @options[:metrics],
              :percentiles  => @options[:percentiles],
              :profile_name => @options[:profile_name],
              :url          => @options[:profile_name].downcase.gsub(/[^\w]+/, "+") }

    # Save it.
    profiles = self.class.load
    profiles[attrs[:url]] = attrs

    Visage::Config::File.open('profiles.yaml') do |file|
      file.truncate(0)
      file << profiles.to_yaml
    end

    true
  else
    false
  end
end
valid?() click to toggle source
# File lib/visage-app/profile.rb, line 80
def valid?
  valid_profile_name?
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.