summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-06-30 22:30:27 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-06-30 22:30:27 +0000
commit34e779fcf2bfed1c6874084af6c99e072c4ecc7f (patch)
treec8d6cf6d26d8b6dfda7b7fe8f814f0e29cfd66de /lib
parent24f07e0686cc9d81452d33daf215fa050ec89129 (diff)
downloadpuppet-34e779fcf2bfed1c6874084af6c99e072c4ecc7f.tar.gz
puppet-34e779fcf2bfed1c6874084af6c99e072c4ecc7f.tar.xz
puppet-34e779fcf2bfed1c6874084af6c99e072c4ecc7f.zip
Significantly redoing metrics. There are now no class variables for metrics, nor no class methods for it.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1350 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet.rb5
-rw-r--r--lib/puppet/metric.rb145
-rw-r--r--lib/puppet/reports/rrdgraph.rb20
-rwxr-xr-xlib/puppet/server/report.rb1
4 files changed, 34 insertions, 137 deletions
diff --git a/lib/puppet.rb b/lib/puppet.rb
index 26b3b8125..71a15fe23 100644
--- a/lib/puppet.rb
+++ b/lib/puppet.rb
@@ -241,11 +241,6 @@ module Puppet
:runinterval => [1800, # 30 minutes
"How often puppetd applies the client configuration; in seconds"]
)
- self.setdefaults("metrics",
- :rrddir => ["$vardir/rrd",
- "The directory where RRD database files are stored."],
- :rrdgraph => [false, "Whether RRD information should be graphed."]
- )
# configuration parameter access and stuff
def self.[](param)
diff --git a/lib/puppet/metric.rb b/lib/puppet/metric.rb
index 4aa2fe3b2..1370a5297 100644
--- a/lib/puppet/metric.rb
+++ b/lib/puppet/metric.rb
@@ -4,135 +4,17 @@ require 'puppet'
module Puppet
# A class for handling metrics. This is currently ridiculously hackish.
class Metric
- def self.init
- @@typemetrics = Hash.new { |typehash,typename|
- typehash[typename] = Hash.new(0)
- }
-
- @@eventmetrics = Hash.new(0)
-
- @@metrics = {}
- end
-
- self.init
-
- def self.clear
- self.init
- end
-
- def self.gather
- self.init
-
- # first gather stats about all of the types
- Puppet::Type.eachtype { |type|
- type.each { |instance|
- hash = @@typemetrics[type]
- hash[:total] += 1
- if instance.managed?
- hash[:managed] += 1
- end
- }
- }
-
- # the rest of the metrics are injected directly by type.rb
- end
-
- def self.add(type,instance,metric,count)
- return unless defined? @@typemetrics
- case metric
- when :outofsync:
- @@typemetrics[type][metric] += count
- when :changes:
- @@typemetrics[type][:changed] += 1
- @@typemetrics[type][:totalchanges] += count
- else
- raise Puppet::DevError, "Unknown metric %s" % metric
- end
- end
-
- # we're currently throwing away the type and instance information
- def self.addevents(type,instance,events)
- return unless defined? @@eventmetrics
- events.each { |event|
- @@eventmetrics[event] += 1
- }
- end
-
- # Iterate across all of the metrics
- def self.each
- @@metrics.each { |name,metric|
- yield metric
- }
- end
-
- # I'm nearly positive this method is used only for testing
- def self.load(ary)
- @@typemetrics = ary[0]
- @@eventmetrics = ary[1]
- end
-
- def self.graph(range = nil)
- @@metrics.each { |name,metric|
- metric.graph(range)
- }
- end
-
- def self.store(time = nil)
- require 'RRD'
- unless time
- time = Time.now.to_i
- end
- @@metrics.each { |name,metric|
- metric.store(time)
- }
- end
-
- def self.tally
- type = self.new("typecount","Types")
- type.newvalue("Number",@@typemetrics.length)
-
- metrics = {
- :total => "Instances",
- :managed => "Managed Instances",
- :outofsync => "Out of Sync Instances",
- :changed => "Changed Instances",
- :totalchanges => "Total Number of Changes",
- }
- total = Hash.new(0)
- @@typemetrics.each { |type,instancehash|
- name = type.name.to_s
- instmet = self.new("type-" + name,name.capitalize)
- metrics.each { |symbol,label|
- instmet.newvalue(symbol.to_s,instancehash[symbol],label)
- total[symbol] += instancehash[symbol]
- }
- }
-
- totalmet = self.new("typetotals","Type Totals")
- metrics.each { |symbol,label|
- totalmet.newvalue(symbol.to_s,total[symbol],label)
- }
-
- eventmet = self.new("events")
- total = 0
- @@eventmetrics.each { |event,count|
- event = event.to_s
- # add the specific event as a value, with the label being a
- # capitalized version with s/_/ /g
- eventmet.newvalue(
- event,
- count,
- event.capitalize.gsub(/_/,' ')
- )
-
- total += count
- }
- eventmet.newvalue("total",total,"Event Total")
- end
+ Puppet.config.setdefaults("metrics",
+ :rrddir => {:default => "$vardir/rrd",
+ :owner => "$user",
+ :group => "$group",
+ :desc => "The directory where RRD database files are stored."
+ },
+ :rrdgraph => [false, "Whether RRD information should be graphed."]
+ )
attr_accessor :type, :name, :value, :label
-
def create
Puppet.config.use(:metrics)
@@ -156,7 +38,8 @@ module Puppet
end
def initialize(name,label = nil)
- @name = name
+ @name = name.to_s
+
if label
@label = label
else
@@ -164,11 +47,6 @@ module Puppet
end
@values = []
- if @@metrics.include?(self.name)
- raise "Somehow created two metrics with name %s" % self.name
- else
- @@metrics[self.name] = self
- end
end
def newvalue(name,value,label = nil)
@@ -183,7 +61,9 @@ module Puppet
end
def graph(range = nil)
+ require 'RRD'
args = [self.path.sub(/rrd$/,"png")]
+
args.push("--title",self.label)
args.push("--imgformat","PNG")
args.push("--interlace")
@@ -212,6 +92,7 @@ module Puppet
end
def store(time)
+ require 'RRD'
unless FileTest.exists?(File.join(Puppet[:rrddir],@name + ".rrd"))
self.create
end
diff --git a/lib/puppet/reports/rrdgraph.rb b/lib/puppet/reports/rrdgraph.rb
new file mode 100644
index 000000000..29eca4aeb
--- /dev/null
+++ b/lib/puppet/reports/rrdgraph.rb
@@ -0,0 +1,20 @@
+require 'puppet'
+
+Puppet::Server::Report.newreport(:rrdgraph) do |report|
+ time = Time.now.to_i
+
+ File.open(File.join(Puppet[:rrddir],"index.html"),"w") { |of|
+ of.puts "<html><body>"
+ report.metrics.each do |name, metric|
+ metric.store(time)
+
+ metric.graph
+
+ of.puts "<img src=%s.png><br>" % name
+ end
+
+ of.puts "</body></html>"
+ }
+end
+
+# $Id$
diff --git a/lib/puppet/server/report.rb b/lib/puppet/server/report.rb
index 7be44fa44..28005e636 100755
--- a/lib/puppet/server/report.rb
+++ b/lib/puppet/server/report.rb
@@ -60,6 +60,7 @@ class Server
def initialize(*args)
super
Puppet.config.use(:reporting)
+ Puppet.config.use(:metrics)
end
def mkclientdir(client, dir)