gnuplot / webplot / access_plot
| 集計結果のプロット定期的に集計結果をプロットしておく方法 集計結果を自動的にプロットしてGIFやPNGに出力するperlのスクリプトを $logfile='/path/to/access_log'; $gnuplot='/path/to/gnuplot'; $imgfile='/path/to/access.png'; 最初にlogファイル,出力するイメージファイル,それからgnuplotのPATH
open(LOG,$logfile);
while(<LOG>){
if(/.html/){
split;
$day = substr($_[3],1,2);
$mon = substr($_[3],4,3);
$year= substr($_[3],8,4);
$count[$day]++;
}
}
close(LOG);
$day=$#count;
$count[$day+1]=$count[$day];
この部分は,前節とほぼ同じですが,標準入力から読み込むのではなく,log 最後の2行は,右端(31日目)のデータがヒストグラムできちんと描かれるよ
& make_gnuplot;
open(GNUPLOT,"| ".$gnuplot);
foreach $i (0..$#plot){ print GNUPLOT $plot[$i]; }
for($i=1;$i<=$#count;$i++){
printf(GNUPLOT "%10d%10dn",$i,$count[$i]);
}
print GNUPLOT "endn";
close(GNUPLOT);
exit 0;
集計結果をgnuplotに与えてプロットする部分です.gnuplotに与える種々の
sub make_gnuplot{
$i=0;
$plot[$i++]=sprintf("set term png colorn");
$plot[$i++]=sprintf("set output '%s'n",$imgfile);
$plot[$i++]=sprintf("set size 0.7,0.7n");
$plot[$i++]=sprintf("set xrange [0:32]n");
$plot[$i++]=sprintf("set yrange [0:*]n");
$plot[$i++]=sprintf("set xtics 1,7,31n");
$plot[$i++]=sprintf("set mxtics 7n");
$plot[$i++]=sprintf("set nokeyn");
$plot[$i++]=sprintf("set gridn");
$plot[$i++]=sprintf("set title '%s %s'n",$mon,$year);
$plot[$i++]=sprintf("plot '-' with stepn");
}
ここでは出力はPNGになっています.以下, set size やset このスクリプトを走らせると,access_logを1ヵ月分集計したグラフができあ ![]() |
