summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2005-06-29 03:11:06 +0000
committerLuke Kanies <luke@madstop.com>2005-06-29 03:11:06 +0000
commit0c4254a9c1bad795a8bcc895cff74b6dd961ba44 (patch)
tree2d512a90e147d020486ff71591ad64202814ac06 /test
parent573d3018a67521f37dbbd46e86c7d1d8b7bc2703 (diff)
downloadpuppet-0c4254a9c1bad795a8bcc895cff74b6dd961ba44.tar.gz
puppet-0c4254a9c1bad795a8bcc895cff74b6dd961ba44.tar.xz
puppet-0c4254a9c1bad795a8bcc895cff74b6dd961ba44.zip
metric testing and graphing now works in the library, although nothing has been done in the language
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@314 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
-rw-r--r--test/other/tc_metrics.rb79
1 files changed, 79 insertions, 0 deletions
diff --git a/test/other/tc_metrics.rb b/test/other/tc_metrics.rb
new file mode 100644
index 000000000..4617d18c9
--- /dev/null
+++ b/test/other/tc_metrics.rb
@@ -0,0 +1,79 @@
+if __FILE__ == $0
+ $:.unshift '..'
+ $:.unshift '../../lib'
+ $puppetbase = "../../../../language/trunk/"
+end
+
+require 'puppet/metric'
+require 'puppet'
+require 'puppet/type'
+require 'test/unit'
+
+# $Id$
+
+class TestMetric < Test::Unit::TestCase
+
+ def gendata
+ totalmax = 1000
+ changemax = 10000
+ eventmax = 10
+ maxdiff = 10
+
+ types = [Puppet::Type::File, Puppet::Type::Package, Puppet::Type::Service]
+ data = [:total, :managed, :outofsync, :changed, :totalchanges]
+ events = [:file_changed, :package_installed, :service_restarted]
+
+ # if this is the first set of data points...
+ typedata = {}
+ eventdata = {}
+ types.each { |type|
+ name = type.name
+ typedata[type] = {}
+ typedata[type][:total] = rand(totalmax)
+ typedata[type][:managed] = rand(typedata[type][:total])
+ typedata[type][:outofsync] = rand(typedata[type][:managed])
+ typedata[type][:changed] = rand(typedata[type][:outofsync])
+ typedata[type][:totalchanges] = rand(changemax)
+ }
+
+ events.each { |event|
+ eventdata[event] = rand(eventmax)
+ }
+
+ return [typedata,eventdata]
+ end
+
+ def setup
+ Puppet[:rrddir] = File.join(Dir.getwd,"rrdtests")
+ Puppet[:rrdgraph] = true
+ Puppet[:loglevel] = :debug
+ end
+
+ def teardown
+ #system("rm -rf rrdtests")
+ end
+
+ def test_fakedata
+ assert_nothing_raised { Puppet::Metric.init }
+ time = Time.now.to_i
+ start = time
+ 10.times {
+ assert_nothing_raised { Puppet::Metric.load(gendata) }
+ assert_nothing_raised { Puppet::Metric.tally }
+ assert_nothing_raised { Puppet::Metric.store(time) }
+ assert_nothing_raised { Puppet::Metric.clear }
+ time += 300
+ }
+ assert_nothing_raised { Puppet::Metric.load(gendata) }
+ assert_nothing_raised { Puppet::Metric.tally }
+ assert_nothing_raised { Puppet::Metric.store(time) }
+ assert_nothing_raised { Puppet::Metric.graph([start,time]) }
+
+ File.open(File.join(Puppet[:rrddir],"index.html"),"w") { |of|
+ of.puts "<html><body>"
+ Puppet::Metric.each { |metric|
+ of.puts "<img src=%s.png><br>" % metric.name
+ }
+ }
+ end
+end