66: def graph(range = nil)
67: unless Puppet.features.rrd? || Puppet.features.rrd_legacy?
68: Puppet.warning "RRD library is missing; cannot graph metrics"
69: return
70: end
71:
72: unit = 60 * 60 * 24
73: colorstack = %w{#00ff00 #ff0000 #0000ff #ffff00 #ff99ff #ff9966 #66ffff #990000 #099000 #000990 #f00990 #0f0f0f #555555 #333333 #ffffff}
74:
75: {:daily => unit, :weekly => unit * 7, :monthly => unit * 30, :yearly => unit * 365}.each do |name, time|
76: file = self.path.sub(/\.rrd$/, "-#{name}.png")
77: args = [file]
78:
79: args.push("--title",self.label)
80: args.push("--imgformat","PNG")
81: args.push("--interlace")
82: i = 0
83: defs = []
84: lines = []
85:
86: values.zip(colorstack).each { |value,color|
87: next if value.nil?
88:
89: defs.push("DEF:#{value[0]}=#{self.path}:#{value[0]}:AVERAGE")
90: lines.push("LINE2:#{value[0]}#{color}:#{value[1]}")
91: }
92: args << defs
93: args << lines
94: args.flatten!
95: if range
96: if Puppet.features.rrd_legacy? && ! Puppet.features.rrd?
97: args.push("--start",range[0],"--end",range[1])
98: else
99: args.push("--start",range[0].to_i.to_s,"--end",range[1].to_i.to_s)
100: end
101: else
102: if Puppet.features.rrd_legacy? && ! Puppet.features.rrd?
103: args.push("--start", Time.now.to_i - time, "--end", Time.now.to_i)
104: else
105: args.push("--start", (Time.now.to_i - time).to_s, "--end", Time.now.to_i.to_s)
106: end
107: end
108:
109: begin
110:
111: if Puppet.features.rrd_legacy? && ! Puppet.features.rrd?
112: RRDtool.graph( args )
113: else
114: RRD.graph( *args )
115: end
116: rescue => detail
117: Puppet.err "Failed to graph #{self.name}: #{detail}"
118: end
119: end
120: end