把數據畫成圖,是我一直想要達到的,今日研究gnuplot,小有成就,下面我只舉一個數據製圖的例子
比如我想畫個每小時nginx日誌500錯的圖
需求:開啓一個http服務,比如80端口
web根目錄爲/var/www/html
實施:
1.先針對nginx日誌進行分析
grep \"\ 500 access.log|wc -l >>/opt/yanchao/500.txt
2.編寫gnuplot腳本爲
500zhitu.sh
set terminal png truecolor
set output "500.png" 輸出文件爲
set autoscale
set key box
set key center at 20,150 表示位置
set xtics 1 x軸沒個點走多少
set ytics 50 y軸沒個點走多少
set yrange [0:1000] y軸座標
set ylabel "500error" y軸註釋
set xrange [01:24] x軸座標
set xlabel "Time" x軸註釋
set style data lines 選擇線型
plot "/home/yanchao/500test5" using 1 w lp lc 3 lw 2 pt 7 ps 2 title "test" 針對於什麼進行畫圖,using 1代表針對第一列進行製圖 後面參數請查看參考手冊
3.cat 500zhitu.sh|gnuplot
4.訪問圖片
想要獲得動態圖片,請修改crontab 你們懂得 我就不多說了
當然樓主給單位做的比這個複雜很多,樓主致力於用shell搭建一個全面的日誌分析,動態站點