I have been doing a lot of work lately with creating new data points to monitor with cacti and when trouble shooting why a new data point is not working I have been running into a bit of an issue. I can see what my script is handing to the cacti poller, I can see what cacti is putting in the RRD file (with increased logging), but I can’t easily see what RRD has done with that data before handing off to cacti. By default RRD store’s the time stamps in Epoch Time (seconds since midnight on Jan 1st, 1970) and data in scientific notation. Now, I don’t know about you, but I can’t read either of those without some help so here is my little Ruby script helper
#!/usr/bin/env ruby
# Author: W. David Nash III
# Version 0.1
# August 3, 2009
count = 0
STDIN.each do|l|
count += 1
printf("%-3i | ",count)
if !l.match(/^\d+/)
header = l.to_s.split
else
(td, data) = l.split(/:/).map
time = Time.at(td.to_i)
printf("%s:", time.strftime("%Y-%m-%d %H:%M:%S"))
data.to_s.split.map do |d|
if (d.eql? "nan") then d = "0.00" end
printf(" | %20.2f", d.chomp)
end
end
if(count == 1)
printf("%20s", "Time")
header.each do |h|
printf(" | %20s",h)
end
end
puts "\n"
end
and you use it like so
rrdtool fetch rra/.rrd AVERAGE -s -1h -r 60 | ./readRRD.rb
and here is some sample output
1 | Time | Heap_Mem_Committed | Heap_Mem_Max | Heap_Mem_Used | Non_Heap_Mem_Commit | Non_Heap_Mem_Init | Non_Heap_Mem_Max | Non_Heap_Mem_Used | CPU_TIME | User_Time | Thread_Count | Peak_Thread_Count | Heap_Mem_Init
2 |
3 | 2009-08-03 13:18:00: | 213295104.00 | 532742144.00 | 130720632.67 | 36405248.00 | 12746752.00 | 100663296.00 | 36383328.00 | 623333333.33 | 531666666.67 | 111.33 | 184.00 | 0.00
4 | 2009-08-03 13:19:00: | 213295104.00 | 532742144.00 | 132090801.60 | 36405248.00 | 12746752.00 | 100663296.00 | 36383328.00 | 1818000000.00 | 1704000000.00 | 111.80 | 184.00 | 0.00
5 | 2009-08-03 13:20:00: | 213295104.00 | 532742144.00 | 122721880.67 | 36405248.00 | 12746752.00 | 100663296.00 | 36383328.00 | 2186666666.70 | 2057500000.00 | 112.92 | 184.00 | 0.00