summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-10-05 21:22:22 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-10-05 21:22:22 +0000
commit8f058a0b1bef40edb7a077e370cd3bb5db241e65 (patch)
tree30bd57658a61fa8ff526dfc1223629f2cfc223b0
parentb8920939ade4d9956a7f3b2ba3a2c77a3f788c58 (diff)
downloadpuppet-8f058a0b1bef40edb7a077e370cd3bb5db241e65.tar.gz
puppet-8f058a0b1bef40edb7a077e370cd3bb5db241e65.tar.xz
puppet-8f058a0b1bef40edb7a077e370cd3bb5db241e65.zip
Fixing the rrdgraph report so that it creates a separate rrd directory for each host
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1735 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/puppet/metric.rb66
-rw-r--r--lib/puppet/reports/rrdgraph.rb16
-rw-r--r--lib/puppet/transaction.rb18
3 files changed, 64 insertions, 36 deletions
diff --git a/lib/puppet/metric.rb b/lib/puppet/metric.rb
index d08fb48b7..6356871b6 100644
--- a/lib/puppet/metric.rb
+++ b/lib/puppet/metric.rb
@@ -8,9 +8,13 @@ module Puppet
:rrddir => {:default => "$vardir/rrd",
:owner => "$user",
:group => "$group",
- :desc => "The directory where RRD database files are stored."
+ :desc => "The directory where RRD database files are stored.
+ Directories for each reporting host will be created under
+ this directory."
},
- :rrdgraph => [false, "Whether RRD information should be graphed."]
+ :rrdgraph => [false, "Whether RRD information should be graphed."],
+ :rrdinterval => ["$runinterval", "How often RRD should expect data.
+ This should match how often the hosts report back to the server."]
)
@@haverrd = false
@@ -26,6 +30,16 @@ module Puppet
attr_accessor :type, :name, :value, :label
+ attr_writer :basedir
+
+ def basedir
+ if defined? @basedir
+ @basedir
+ else
+ Puppet[:rrddir]
+ end
+ end
+
def create
Puppet.config.use(:metrics)
@@ -33,7 +47,7 @@ module Puppet
args = [
path,
"--start", Time.now.to_i - 5,
- "--step", "300", # XXX Defaulting to every five minutes, but prob bad
+ "--step", Puppet[:rrdinterval]
]
@values.each { |value|
@@ -48,29 +62,6 @@ module Puppet
end
end
- def initialize(name,label = nil)
- @name = name.to_s
-
- if label
- @label = label
- else
- @label = name.to_s.capitalize.gsub("_", " ")
- end
-
- @values = []
- end
-
- def newvalue(name,value,label = nil)
- unless label
- label = name.to_s.capitalize.gsub("_", " ")
- end
- @values.push [name,label,value]
- end
-
- def path
- return File.join(Puppet[:rrddir],@name + ".rrd")
- end
-
def graph(range = nil)
unless @@haverrd
Puppet.warning "RRD library is missing; cannot graph metrics"
@@ -105,6 +96,29 @@ module Puppet
end
end
+ def initialize(name,label = nil)
+ @name = name.to_s
+
+ if label
+ @label = label
+ else
+ @label = name.to_s.capitalize.gsub("_", " ")
+ end
+
+ @values = []
+ end
+
+ def path
+ return File.join(self.basedir, @name + ".rrd")
+ end
+
+ def newvalue(name,value,label = nil)
+ unless label
+ label = name.to_s.capitalize.gsub("_", " ")
+ end
+ @values.push [name,label,value]
+ end
+
def store(time)
unless @@haverrd
Puppet.warning "RRD library is missing; cannot store metrics"
diff --git a/lib/puppet/reports/rrdgraph.rb b/lib/puppet/reports/rrdgraph.rb
index 29eca4aeb..0fb7e2ea7 100644
--- a/lib/puppet/reports/rrdgraph.rb
+++ b/lib/puppet/reports/rrdgraph.rb
@@ -3,9 +3,23 @@ require 'puppet'
Puppet::Server::Report.newreport(:rrdgraph) do |report|
time = Time.now.to_i
- File.open(File.join(Puppet[:rrddir],"index.html"),"w") { |of|
+ host = report.host
+
+ hostdir = File.join(Puppet[:rrddir], host)
+
+ unless File.directory?(hostdir)
+ # Some hackishness to create the dir
+ config = Puppet::Config.new
+ config.setdefaults(:reports, :hostdir => [hostdir, "eh"])
+
+ # This creates the dir.
+ config.use(:reports)
+ end
+
+ File.open(File.join(hostdir, "index.html"),"w") { |of|
of.puts "<html><body>"
report.metrics.each do |name, metric|
+ metric.basedir = hostdir
metric.store(time)
metric.graph
diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb
index 89b321f99..d19ef59ac 100644
--- a/lib/puppet/transaction.rb
+++ b/lib/puppet/transaction.rb
@@ -37,7 +37,7 @@ class Transaction
if skip
child.warning "Skipping because of failed dependencies"
- @objectmetrics[:skipped] += 1
+ @resourcemetrics[:skipped] += 1
return []
end
end
@@ -63,7 +63,7 @@ class Transaction
end
if changes.length > 0
- @objectmetrics[:out_of_sync] += 1
+ @resourcemetrics[:out_of_sync] += 1
end
childevents = changes.collect { |change|
@@ -92,7 +92,7 @@ class Transaction
# if we ever get to that point
unless events.nil? or (events.is_a?(Array) and events.empty?)
change.changed = true
- @objectmetrics[:applied] += 1
+ @resourcemetrics[:applied] += 1
end
events
@@ -167,7 +167,7 @@ class Transaction
events = []
if (self.ignoretags or tags.nil? or child.tagged?(tags))
if self.ignoreschedules or child.scheduled?
- @objectmetrics[:scheduled] += 1
+ @resourcemetrics[:scheduled] += 1
# Perform the actual changes
seconds = thinmark do
@@ -215,7 +215,7 @@ class Transaction
def initialize(objects)
@objects = objects
- @objectmetrics = {
+ @resourcemetrics = {
:total => @objects.length,
:out_of_sync => 0, # The number of objects that had changes
:applied => 0, # The number of objects fixed
@@ -252,7 +252,7 @@ class Transaction
# Generate a transaction report.
def report
- @objectmetrics[:failed] = @failures.find_all do |name, num|
+ @resourcemetrics[:failed] = @failures.find_all do |name, num|
num > 0
end.length
@@ -273,7 +273,7 @@ class Transaction
end
# Add all of the metrics related to object count and status
- @report.newmetric(:objects, @objectmetrics)
+ @report.newmetric(:resources, @resourcemetrics)
# Record the relative time spent in each object.
@report.newmetric(:time, @timemetrics)
@@ -360,12 +360,12 @@ class Transaction
# to them in any way.
begin
obj.send(callback)
- @objectmetrics[:restarted] += 1
+ @resourcemetrics[:restarted] += 1
rescue => detail
obj.err "Failed to call %s on %s: %s" %
[callback, obj, detail]
- @objectmetrics[:failed_restarts] += 1
+ @resourcemetrics[:failed_restarts] += 1
if Puppet[:debug]
puts detail.backtrace