Class: Visage::Profile
- Inherits:
-
Object
- Object
- Visage::Profile
- Defined in:
- lib/visage-app/profile.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#hosts ⇒ Object
readonly
Returns the value of attribute hosts.
-
#metrics ⇒ Object
readonly
Returns the value of attribute metrics.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#selected_hosts ⇒ Object
readonly
Returns the value of attribute selected_hosts.
-
#selected_metrics ⇒ Object
readonly
Returns the value of attribute selected_metrics.
Class Method Summary collapse
Instance Method Summary collapse
- #graphs ⇒ Object
-
#initialize(opts = {}) ⇒ Profile
constructor
A new instance of Profile.
-
#method_missing(method) ⇒ Object
Hashed based access to @options.
- #private_id ⇒ Object
- #save ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(opts = {}) ⇒ Profile
Returns a new instance of Profile.
40 41 42 43 44 45 46 |
# File 'lib/visage-app/profile.rb', line 40 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 end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method) ⇒ Object
Hashed based access to @options.
49 50 51 |
# File 'lib/visage-app/profile.rb', line 49 def method_missing(method) @options[method] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
11 12 13 |
# File 'lib/visage-app/profile.rb', line 11 def errors @errors end |
#hosts ⇒ Object (readonly)
Returns the value of attribute hosts.
11 12 13 |
# File 'lib/visage-app/profile.rb', line 11 def hosts @hosts end |
#metrics ⇒ Object (readonly)
Returns the value of attribute metrics.
11 12 13 |
# File 'lib/visage-app/profile.rb', line 11 def metrics @metrics end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/visage-app/profile.rb', line 11 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/visage-app/profile.rb', line 11 def @options end |
#selected_hosts ⇒ Object (readonly)
Returns the value of attribute selected_hosts.
11 12 13 |
# File 'lib/visage-app/profile.rb', line 11 def selected_hosts @selected_hosts end |
#selected_metrics ⇒ Object (readonly)
Returns the value of attribute selected_metrics.
11 12 13 |
# File 'lib/visage-app/profile.rb', line 11 def selected_metrics @selected_metrics end |
Class Method Details
.all(opts = {}) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/visage-app/profile.rb', line 33 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.map { |prof| self.new(prof) } end |
.get(id) ⇒ Object
27 28 29 30 31 |
# File 'lib/visage-app/profile.rb', line 27 def self.get(id) url = id.downcase.gsub(/[^\w]+/, "+") profiles = self.load profiles[url] ? self.new(profiles[url]) : nil end |
.load ⇒ Object
23 24 25 |
# File 'lib/visage-app/profile.rb', line 23 def self.load Visage::Config::File.load('profiles.yaml', :create => true, :ignore_bundled => true) || {} end |
.old_format? ⇒ Boolean
14 15 16 17 18 19 20 21 |
# File 'lib/visage-app/profile.rb', line 14 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 |
Instance Method Details
#graphs ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/visage-app/profile.rb', line 80 def graphs graphs = [] hosts = @options[:hosts] metrics = @options[:metrics] 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) end end graphs end |
#private_id ⇒ Object
106 107 108 |
# File 'lib/visage-app/profile.rb', line 106 def private_id Digest::MD5.hexdigest("#{@options[:url]}\n") end |
#save ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/visage-app/profile.rb', line 53 def save if valid? # Construct record. attrs = { :hosts => @options[:hosts], :metrics => @options[:metrics], :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? ⇒ Boolean
76 77 78 |
# File 'lib/visage-app/profile.rb', line 76 def valid? valid_profile_name? end |