summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Wolfe <jes5199@gmail.com>2010-09-24 16:51:20 -0700
committerMarkus Roberts <Markus@reality.com>2010-09-28 15:36:24 -0700
commitd057b90bba4ffe7174e9af789835d5528e8a200d (patch)
treede61a963851069abe3e77866d6a0f57f5a2f78bf
parent66cf3a925b4b6d9b40cbdf95f2be6575bb05a881 (diff)
downloadpuppet-d057b90bba4ffe7174e9af789835d5528e8a200d.tar.gz
puppet-d057b90bba4ffe7174e9af789835d5528e8a200d.tar.xz
puppet-d057b90bba4ffe7174e9af789835d5528e8a200d.zip
Fix #4726 Update puppet rrdtool metric code to support modern rrd ruby bindings
The rrd project has been shipping ruby bindings since 1.3.0, and the old rrdtool ruby library is no longer being maintained. This patch is based upon Davor Ocelic's submitted code, with the addition that I've added conditionals so it can still call the old rrdtool library if a modern rrd is not installed.
-rw-r--r--lib/puppet/feature/base.rb3
-rw-r--r--lib/puppet/util/metric.rb47
2 files changed, 40 insertions, 10 deletions
diff --git a/lib/puppet/feature/base.rb b/lib/puppet/feature/base.rb
index c153fba98..c983f5c12 100644
--- a/lib/puppet/feature/base.rb
+++ b/lib/puppet/feature/base.rb
@@ -27,7 +27,8 @@ Puppet.features.add :diff, :libs => %w{diff/lcs diff/lcs/hunk}
Puppet.features.add(:augeas, :libs => ["augeas"])
# We have RRD available
-Puppet.features.add(:rrd, :libs => ["RRDtool"])
+Puppet.features.add(:rrd_legacy, :libs => ["RRDtool"])
+Puppet.features.add(:rrd, :libs => ["RRD"])
# We have OpenSSL
Puppet.features.add(:openssl, :libs => ["openssl"])
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}"