lib/visage-app/profile.rb in visage-app-2.0.5 vs lib/visage-app/profile.rb in visage-app-2.1.0
- old
+ new
@@ -7,10 +7,11 @@
require 'digest/md5'
module Visage
class Profile
attr_reader :options, :selected_hosts, :hosts, :selected_metrics, :metrics,
+ :selected_percentiles, :percentiles,
:name, :errors
def self.old_format?
profiles = Visage::Config::File.load('profiles.yaml', :create => true, :ignore_bundled => true) || {}
profiles.each_pair do |name, attrs|
@@ -31,20 +32,22 @@
end
def self.all(opts={})
sort = opts[:sort]
profiles = self.load
- profiles = sort == "name" ? profiles.sort_by {|k,v| v[:profile_name]}.map {|i| i.last } : profiles.values
+ 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
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[: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
# Hashed based access to @options.
def method_missing(method)
@options[method]
@@ -53,10 +56,11 @@
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
@@ -76,13 +80,14 @@
def valid?
valid_profile_name?
end
def graphs
- graphs = []
- hosts = @options[:hosts]
- metrics = @options[:metrics]
+ 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|
@@ -94,10 +99,11 @@
end
attrs.each_pair do |plugin, instances|
graphs << Visage::Graph.new(:host => host,
:plugin => plugin,
- :instances => instances)
+ :instances => instances,
+ :percentiles => percentiles)
end
end
graphs
end