ruby
(rrdfetch_in_localtime.rb)
#!/usr/bin/env ruby f = open("|rrdtool fetch #{ARGV[0]} AVERAGE") f.each do |line| if /^(\d+):/ =~ line temp = line.split() temp[0] = Time.at($1.to_i).strftime("%Y/%m/%d %H:%M:%S") puts temp.join(" ") end end f.close
$ rrdtool fetch localhost_2.rrd AVERAGE ds0 ds1 1331738100: -nan -nan 1331738400: -nan -nan ... 1331822400: -nan -nan 1331822700: 1.9756373938e+01 4.4640226629e+01 1331823000: 4.9390934844e+00 1.1160056657e+01 1331823300: 4.9390934844e+00 1.1160056657e+01 1331823600: -nan -nan ... $ $ ./rrdfetch_in_localtime.rb localhost_2.rrd 2012/03/15 00:15:00 -nan -nan 2012/03/15 00:20:00 -nan -nan ... 2012/03/15 23:40:00 -nan -nan 2012/03/15 23:45:00 1.9756373938e+01 4.4640226629e+01 2012/03/15 23:50:00 4.9390934844e+00 1.1160056657e+01 2012/03/15 23:55:00 4.9390934844e+00 1.1160056657e+01 2012/03/16 00:00:00 -nan -nan ...
awk
$ rrdtool fetch localhost_2.rrd AVERAGE | awk '{print strftime("%Y/%m/%d %H:%M:%S",$1),$2,$3}'
参照したURL:
http://pooh.gr.jp/?p=82
wikipedia:UNIX時間