Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
cronで15分毎にload averageを取得して、それをgnuplotでpngのグラフに書き出すrubyスクリプト gnuplotが必要です。 sudo apt-get install gnuplot cronへの登録例(15分毎の実行) */15 * * * * /var/www/loadaverage.rb
#!/usr/bin/env ruby
# please install gnuplot
# sudo apt-get install gnuplot
# crontab
# */15 * * * * /var/www/loadaverage.rb
logname = "/var/www/loadaverage/#{'%Y%m%d')}.log"
pngname = "/var/www/load.png""#{logname}", "a") do |f|
f.puts(("%s") + " " + `uptime`.split("average: ").last.split(", ")[2])
script = <<'EOS'.sub("PNGNAME", "#{pngname}").sub("LOGNAME", "#{logname}")
set terminal png
set output "PNGNAME"
set xdata time
set timefmt "%s"
set grid y
set format x "%H"
set title "Load Average (Daily)"
set size 0.8, 0.5
plot "LOGNAME" using 1:2 title "Load" with lines
system("echo '#{script}' | gnuplot")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment