summaryrefslogtreecommitdiffstats
path: root/test/util/metrics.rb
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-02-08 05:11:49 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-02-08 05:11:49 +0000
commit1756bec99b9136463e5d35f1de4119b813ce40cc (patch)
tree380c1f37b2238fd37842a3b9934f6be16f36b450 /test/util/metrics.rb
parenta216df2bcb304ad379e152f2f59ef7d942f54f3b (diff)
downloadpuppet-1756bec99b9136463e5d35f1de4119b813ce40cc.tar.gz
puppet-1756bec99b9136463e5d35f1de4119b813ce40cc.tar.xz
puppet-1756bec99b9136463e5d35f1de4119b813ce40cc.zip
Fixing #484. Moving unit tests at the same time.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2181 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test/util/metrics.rb')
-rwxr-xr-xtest/util/metrics.rb81
1 files changed, 81 insertions, 0 deletions
diff --git a/test/util/metrics.rb b/test/util/metrics.rb
new file mode 100755
index 000000000..c4e375e7b
--- /dev/null
+++ b/test/util/metrics.rb
@@ -0,0 +1,81 @@
+#!/usr/bin/env ruby
+
+$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/
+
+require 'puppet'
+require 'puppet/util/metric'
+require 'puppettest'
+require 'puppet/type'
+
+if Puppet.features.rrd?
+ class TestMetric < Test::Unit::TestCase
+ include PuppetTest
+
+ def gendata
+ totalmax = 1000
+ changemax = 1000
+ eventmax = 10
+ maxdiff = 10
+
+ types = [Puppet.type(:file), Puppet.type(:package), Puppet.type(:package)]
+ data = [:total, :managed, :outofsync, :changed, :totalchanges]
+ events = [:file_changed, :package_installed, :service_started]
+
+ # if this is the first set of data points...
+ typedata = Hash.new { |typehash,type|
+ typehash[type] = Hash.new(0)
+ }
+ eventdata = Hash.new(0)
+ typedata = {}
+ typedata[:total] = rand(totalmax)
+ typedata[:managed] = rand(typedata[:total])
+ typedata[:outofsync] = rand(typedata[:managed])
+ typedata[:changed] = rand(typedata[:outofsync])
+ typedata[:totalchanges] = rand(changemax)
+
+ events.each { |event|
+ eventdata[event] = rand(eventmax)
+ }
+
+ return {:typedata => typedata, :eventdata => eventdata}
+ end
+
+ def rundata(report, time)
+ assert_nothing_raised {
+ gendata.each do |name, data|
+ report.newmetric(name, data)
+ end
+ report.metrics.each { |n, m| m.store(time) }
+ }
+ end
+
+ def setup
+ super
+ Puppet[:rrdgraph] = true
+ end
+
+ def test_fakedata
+ report = Puppet::Transaction::Report.new
+ time = Time.now.to_i
+ start = time
+ 10.times {
+ rundata(report, time)
+ time += 300
+ }
+ rundata(report, time)
+
+ report.metrics.each do |n, m| m.graph end
+
+ File.open(File.join(Puppet[:rrddir],"index.html"),"w") { |of|
+ of.puts "<html><body>"
+ report.metrics.each { |name, metric|
+ of.puts "<img src=%s.png><br>" % metric.name
+ }
+ }
+ end
+ end
+else
+ $stderr.puts "Missing RRD library -- skipping metric tests"
+end
+
+# $Id$