用gnuplot給採集數據繪圖

    最近作了KVM&SPICE的性能測試,對大量的性能參數進行採集,主要用到vmstat 和nload工具來統計,監控腳本以下:bash

dr=/tmp/test/test_1  && type=click && mkdir -p ${dr} && echo "vmstat 1 300 > 工具

${dr}/vmstat_${type}.txt && " |/bin/bash  && echo "nload  -t 1000 -U k -u k > ${dr}/nload_${type}.txt &" |/bin/bash  && sleep 300 && ps aux |grep nload |awk '{print $2}' | xargs  kill -9  || echo "Done"  性能

其中: 測試

dr=/tmp/test/test_1  表示監控數據文件放置的文件夾spa

type=click 表示點擊操做orm

echo "vmstat 1 300 > ${dr}/vmstat_${type}.txt & " |/bin/bash 每一秒監控一次,一共監控300秒,(來自於最大時間窗口5分鐘)並放置在後臺執行。進程

echo "nload  -t 1000 -U k -u k > ${dr}/nload_${type}.txt &" |/bin/bash 表示間隔1000毫秒採集一次數據, -U k -u k 表示單位爲kBit/s 圖片

sleep 300 && ps aux |grep nload |awk '{print $2}' | xargs  kill -9   這個表示300秒事後,Killnload進程。ip

 

產生大量數據,要對這些數據繪圖仍是要有些技巧。terminal

    一幅圖上畫多條曲線,能夠用plot 後面跟幾個曲線定義,也能夠用replot,可是replot並不能讀取原來已經繪製的圖片,因此還須要從新set output '${path}' 這樣連同前面的曲線和replot的曲線會繪製到後面的文件中。這點要切記。

    多幅圖畫在同一屏上,主要利用了multiplot模式來繪製,可是對於幾個大量數據拼成一屏幕,仍是要有點技巧的。同時要處理座標系統,X,Y軸。

分享兩個腳本,能夠在上面作些修改,描出來的圖更顯專業。

--------------------------------------------------------------------------------------------------------------------------

root@kvm gnuplot_script]# cat test_1_click_load.plot 

set terminal png

set output '/tmp/test/test_1/deal_with/images/test_1_click_load.png'

set size 1,1

set origin 0,0 

set multiplot

set size 1,0.5

set origin 0,0.5

set yrange[0:5]

set title 'Load'

set xlabel 'Time(second)'

set ylabel 'Load number'

plot '/tmp/test/test_1/deal_with/vmstat_click.txt' using 1:2 with linespoints

set size 1,0.5

set origin 0,0

set yrange[0:5]

set title 'Blocked Processes'

set xlabel 'Time(second)'

set ylabel 'Bolcked Processes Number'

plot '/tmp/test/test_1/deal_with/vmstat_click.txt' using 1:3 with linespoints 

unset multiplot

reset

--------------------------------------------------------------------------------------------------------------------------

set terminal png

set size 1,1

set origin 0,0

set output '/tmp/test/test_1/deal_with/images/test_1_click_io.png'

set multiplot

set size 0.5,0.5

set origin 0,0.5

plot '/tmp/test/test_1/deal_with/vmstat_click.txt' using 1:8  with lines title 'swap_in'

set size 0.5,0.5

set origin 0,0

plot '/tmp/test/test_1/deal_with/vmstat_click.txt' using 1:9 with lines title 'swap_out'

set size 0.5,0.5

set origin 0.5,0.5

plot '/tmp/test/test_1/deal_with/vmstat_click.txt' using 1:10 with lines  title 'block_in'

set size 0.5,0.5

set origin 0.5,0

plot '/tmp/test/test_1/deal_with/vmstat_click.txt' using 1:11 with lines title 'block_out'

unset multiplot

reset

相關文章
相關標籤/搜索