diff options
author | Jesse Wolfe <jes5199@gmail.com> | 2010-10-04 15:37:19 -0700 |
---|---|---|
committer | Jesse Wolfe <jes5199@gmail.com> | 2010-10-04 15:37:23 -0700 |
commit | 6acfdba87bdffe4afd6e00cbf3695160f7994357 (patch) | |
tree | 30d09c8a40073f6d9fa95c8bef0d4a18b462c348 /lib/puppet/util | |
parent | 1a00c07971c4297bce1b3e0edee3b6b3399e17bb (diff) | |
parent | 6dd1930ff66f6e89ff3d7edba9cc20126d9cd9a3 (diff) | |
download | puppet-6acfdba87bdffe4afd6e00cbf3695160f7994357.tar.gz puppet-6acfdba87bdffe4afd6e00cbf3695160f7994357.tar.xz puppet-6acfdba87bdffe4afd6e00cbf3695160f7994357.zip |
Partial merge to 2.6.2rc1 : Merge commits 'd057b90' and '6dd1930' into next
This commit merges in d057b90 with the addition of commit 6dd1930 to fix
some tests that are confined to machines where rrd is installed.
Diffstat (limited to 'lib/puppet/util')
-rw-r--r-- | lib/puppet/util/metric.rb | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/lib/puppet/util/metric.rb b/lib/puppet/util/metric.rb index 7e14a5fec..00898472f 100644 --- a/lib/puppet/util/metric.rb +++ b/lib/puppet/util/metric.rb @@ -31,9 +31,12 @@ class Puppet::Util::Metric start ||= Time.now.to_i - 5 - @rrd = RRDtool.new(self.path) args = [] + if Puppet.features.rrd_legacy? && ! Puppet.features.rrd? + @rrd = RRDtool.new(self.path) + end + values.each { |value| # the 7200 is the heartbeat -- this means that any data that isn't # more frequently than every two hours gets thrown away @@ -42,14 +45,22 @@ class Puppet::Util::Metric args.push "RRA:AVERAGE:0.5:1:300" begin - @rrd.create( Puppet[:rrdinterval].to_i, start, args) + if Puppet.features.rrd_legacy? && ! Puppet.features.rrd? + @rrd.create( Puppet[:rrdinterval].to_i, start, args) + else + RRD.create( self.path, '-s', Puppet[:rrdinterval].to_i.to_s, '-b', start.to_i.to_s, *args) + end rescue => detail raise "Could not create RRD file #{path}: #{detail}" end end def dump - puts @rrd.info + if Puppet.features.rrd_legacy? && ! Puppet.features.rrd? + puts @rrd.info + else + puts RRD.info self.path + end end def graph(range = nil) @@ -82,14 +93,26 @@ class Puppet::Util::Metric args << lines args.flatten! if range - args.push("--start",range[0],"--end",range[1]) + if Puppet.features.rrd_legacy? && ! Puppet.features.rrd? + args.push("--start",range[0],"--end",range[1]) + else + args.push("--start",range[0].to_i.to_s,"--end",range[1].to_i.to_s) + end else - args.push("--start", Time.now.to_i - time, "--end", Time.now.to_i) + if Puppet.features.rrd_legacy? && ! Puppet.features.rrd? + args.push("--start", Time.now.to_i - time, "--end", Time.now.to_i) + else + args.push("--start", (Time.now.to_i - time).to_s, "--end", Time.now.to_i.to_s) + end end begin #Puppet.warning "args = #{args}" - RRDtool.graph( args ) + if Puppet.features.rrd_legacy? && ! Puppet.features.rrd? + RRDtool.graph( args ) + else + RRD.graph( *args ) + end rescue => detail Puppet.err "Failed to graph #{self.name}: #{detail}" end @@ -114,13 +137,15 @@ class Puppet::Util::Metric end def store(time) - unless Puppet.features.rrd? + unless Puppet.features.rrd? || Puppet.features.rrd_legacy? Puppet.warning "RRD library is missing; cannot store metrics" return end self.create(time - 5) unless FileTest.exists?(self.path) - @rrd ||= RRDtool.new(self.path) + if Puppet.features.rrd_legacy? && ! Puppet.features.rrd? + @rrd ||= RRDtool.new(self.path) + end # XXX this is not terribly error-resistant args = [time] @@ -133,7 +158,11 @@ class Puppet::Util::Metric arg = args.join(":") template = temps.join(":") begin - @rrd.update( template, [ arg ] ) + if Puppet.features.rrd_legacy? && ! Puppet.features.rrd? + @rrd.update( template, [ arg ] ) + else + RRD.update( self.path, '-t', template, arg ) + end #system("rrdtool updatev #{self.path} '#{arg}'") rescue => detail raise Puppet::Error, "Failed to update #{self.name}: #{detail}" |