Revision e6c75845
Added by Ohad Levy about 14 years ago
- ID e6c7584526bd246b50398348f4b2e20465a46719
app/models/fact_value.rb | ||
---|---|---|
# returns the sum of each value, e.g. how many machines with 2,4...n cpu's
|
||
def self.count_each(fact)
|
||
hash = {}
|
||
find_each(:select => "value", :joins => :fact_name, :conditions => {:fact_names => {:name => fact}}) do |fv|
|
||
all(:select => "value", :joins => :fact_name, :conditions => {:fact_names => {:name => fact}}).each do |fv|
|
||
value = fv.value.strip.humanize
|
||
if hash[value].nil?
|
||
hash[value] = 1
|
app/models/host.rb | ||
---|---|---|
def params
|
||
parameters = {}
|
||
# read common parameters
|
||
CommonParameter.find_each {|p| parameters.update Hash[p.name => p.value] }
|
||
CommonParameter.all.each {|p| parameters.update Hash[p.name => p.value] }
|
||
# read domain parameters
|
||
domain.domain_parameters.each {|p| parameters.update Hash[p.name => p.value] } unless domain.nil?
|
||
# read group parameters only if a host belongs to a group
|
||
... | ... | |
data[:resources] = []
|
||
data[:runtime_labels] = [ ['datetime', "Time" ],['number', "Config Retrival"], ['number', 'Total']]
|
||
data[:resources_labels] = [ ['datetime','Time']] + Report::METRIC.map{|metric| ['number', metric] }
|
||
reports.recent(timerange).find_each do |r|
|
||
reports.recent(timerange).each do |r|
|
||
data[:runtime] << [r.reported_at.getlocal, r.config_retrival, r.runtime ]
|
||
data[:resources] << [r.reported_at.getlocal, r.status.sort.map(&:last)].flatten
|
||
end
|
app/models/report.rb | ||
---|---|---|
# set default of 0 per metric
|
||
metrics = {}
|
||
METRIC.each {|m| metrics[m] = 0 }
|
||
host.reports.recent(time).find_each(:select => "status") do |r|
|
||
host.reports.recent(time).all(:select => "status").each do |r|
|
||
metrics.each_key do |m|
|
||
metrics[m] += r.status(m)
|
||
end
|
Also available in: Unified diff
fixes #231 - find_each LocalJumpError (no block given)