Last active
March 20, 2016 15:24
-
-
Save moyashi/5345306 to your computer and use it in GitHub Desktop.
cronで15分毎にload averageを取得して、それをgnuplotでpngのグラフに書き出すrubyスクリプト gnuplotが必要です。 sudo apt-get install gnuplot cronへの登録例(15分毎の実行) */15 * * * * /var/www/loadaverage.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# please install gnuplot | |
# sudo apt-get install gnuplot | |
# crontab | |
# */15 * * * * /var/www/loadaverage.rb | |
logname = "/var/www/loadaverage/#{Time.now.strftime('%Y%m%d')}.log" | |
pngname = "/var/www/load.png" | |
File.open("#{logname}", "a") do |f| | |
f.puts((Time.now+32400).strftime("%s") + " " + `uptime`.split("average: ").last.split(", ")[2]) | |
end | |
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 | |
EOS | |
system("echo '#{script}' | gnuplot") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment