打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
利用gnuplot繪圖來監測系統資訊

利用gnuplot繪圖來監測系統資訊

檔案位於:- flyfox @ 2:36 pm

利用gnuplot繪圖來監測系統資訊:
作者:衡山飛狐
出處:HappyLinux,Just for fun!


本 著作 係採用 Creative Commons 授權條款授權.

1.1 gnuplot介紹:


gnuplot 是一個命令導向的交談式的繪圖軟體,在 1986 年由 Colin Kelley 和 Thomas Williams 發展而成,gnuplot 的功能就是把數值資料和數學函數轉換成容易觀察的平面或立體的圖形,gnuplot 並不是一般常見的美工繪圖軟體,也不是從事數學運算的程式,它最適合的是在科學研究的過程中,代替研究人員完成數據資料繪製與理論模型比對等機械化的工作,來加速研究的進行。摘錄自http://phi.sinica.edu.tw/aspac/reports/95/95006/chap1.html#1.1

1.2 利用MRTG繪圖限制很多:


如果用MRTG來繪圖,MRTG只能處理2個值及整數部份,例如在我的系統裡用lm_sensors所測得的電壓資料就有VCore 1、VCore 2、+3.3V、+5V、+12V、-12V、-5V、V5SB、VBat九種電壓值,用MRTG就無法呈現在一張圖中了,而且小數點後的值是無效的,例如我的MRTGVCore 1、VCore 2(X100倍)所顯示的圖形:

再來比較利用gnuplot所產生的圖形:

所以如果用MRTG來繪圖,限制很多,圖形又千篇一律。

2.1 需要的工具:


如果系統中沒有安裝gnuplot,請安裝。
如果系統中沒有安裝lm_sensors(Hardware Sensors Monitoring),請安裝。

2.2 利用gnuplot產生系統資訊圖表的兩個例子:


2.2.1:CPU及及系統電壓
在本系統中,當下了sensors的指令,所顯示的資訊如下:

eeprom-i2c-0-50
Adapter: SMBus nForce2 adapter at 5000
Memory type: DDR SDRAM DIMM
Memory size (MB): 256

w83627hf-isa-0290
Adapter: ISA adapter
VCore 1: +1.58 V (min = +1.89 V, max = +2.29 V)
VCore 2: +1.58 V (min = +1.89 V, max = +2.29 V)
+3.3V: +2.59 V (min = +2.82 V, max = +3.79 V)
+5V: +4.92 V (min = +4.38 V, max = +4.30 V)
+12V: +11.93 V (min = +13.91 V, max = +4.26 V)
-12V: -7.20 V (min = -11.47 V, max = -3.40 V)
-5V: -5.39 V (min = +4.76 V, max = +0.39 V)
V5SB: +5.46 V (min = +2.82 V, max = +5.75 V)
VBat: +3.10 V (min = +1.42 V, max = +1.62 V)
fan1: 2045 RPM (min = 8881 RPM, div = 4)
fan2: 0 RPM (min = 2836 RPM, div = 4)
fan3: 3375 RPM (min = 969 RPM, div = 8 )
temp1: +37°C (high = +69°C, hyst = -108°C) sensor = thermistor
temp2: +54.5°C (high = +100°C, hyst = +95°C) sensor = thermistor
temp3: +37.5°C (high = +100°C, hyst = +95°C) sensor = thermistor
vid: +2.100 V
alarms:
beep_enable:
Sound alarm disabled

其中的VCore 1、VCore 2、+3.3V、+5V、+12V、-12V、-5V、V5SB、VBat電壓值變化圖就是本小節所要產生的。
首先寫個shell來產生給gnuplot的data檔。
gnuplot_v.sh

#!/bin/sh
VCore_1=`sensors | grep "VCore 1" | awk ‘{print $3}‘| cut -c 2-5 `
VCore_2=`sensors | grep "VCore 2" | awk ‘{print $3}‘| cut -c 2-5 `
p_3_3V=`sensors | grep "+3.3V" | awk ‘{print $2}‘| cut -c 2-5 `
p_5V=`sensors | grep "+5V" |awk ‘{print $2}‘| cut -c 2-5 `
p_12V=`sensors | grep "+12V" |awk ‘{print $2}‘| cut -c 2-5 `
m_12V=`sensors | grep "\-12V" |awk ‘{print $2}‘| cut -c 1-5 `
m_5V=`sensors | grep "\-5V" |awk ‘{print $2}‘| cut -c 1-5 `
V5SB=`sensors | grep "V5SB" | awk ‘{print $2}‘| cut -c 2-5 `
VBat=`sensors | grep "VBat" | awk ‘{print $2}‘| cut -c 2-5 `
time=`date +%Y%m%d%H%M%S`
echo "$time     $VCore_1        $VCore_2        $p_3_3V $p_5V   $p_12V  $m_12V  $m_5V   $V5SB   $VBat" >> /usr/share/sensor/gnuplot_v.data
gnuplot /usr/share/sensor/gnuplot_v.script > /var/www/localhost/htdocs/gnuplot_v.png

再來寫個gnuplot的script檔
gnuplot_v.script

###################################
#  gnuplot script for CPU & System Volte.
http://www.happylinux.tw/
#  Author:flyfox@gen2.homeip.net
#  File created:  Fri JUL 16 2005
#  Last updated:  Sat JUL 17 2005
###################################
set term png
set timefmt "%Y%m%d%H%M"
set notime
set data style lines
set grid
set autoscale x
set autoscale y
set yrange [-10 : 15]
set mytics 5
set title "CPU & System volte"
set xlabel "Time"
set xdata time
set ylabel "Volte"
set timestamp "Created: %b %d, %Y at %H:%M" top 12,-4.5
        plot    "/usr/share/sensor/gnuplot_v.data" using 1:2 title ‘VCore_1‘,\
                "/usr/share/sensor/gnuplot_v.data" using 1:3 title ‘VCore_2‘,\
                "/usr/share/sensor/gnuplot_v.data" using 1:4 title ‘+3.3V‘,\
                "/usr/share/sensor/gnuplot_v.data" using 1:5 title ‘+5V‘,\
                "/usr/share/sensor/gnuplot_v.data" using 1:6 title ‘+12V‘,\
                "/usr/share/sensor/gnuplot_v.data" using 1:7 title ‘-12V‘,\
                "/usr/share/sensor/gnuplot_v.data" using 1:8 title ‘-5V‘,\
                "/usr/share/sensor/gnuplot_v.data" using 1:9 title ‘V5SB‘,\
                "/usr/share/sensor/gnuplot_v.data" using 1:10 title ‘VBat‘

排入crontab排程

*/5 * * * * /usr/bin/gnuplot_v.sh > /dev/null 2>&1

  • 若要更精細的圖形,可縮短時間,若不想要每次都立即產生圖形可將/usr/bin/gnuplot_v.sh最後一行另外再執行。
    CPU及及系統電壓圖例:

    2.2.2:CPU及系統溫度
    本例則擷取temp1、temp2及temp3三個DATA來產生CPU及系統溫度圖表。
    首先寫個shell來產生給gnuplot的data檔。
    gnuplot_cpu_temp.sh

    #!/bin/sh
    systemp_1=`sensors | grep temp3 |awk ‘{print $2}‘|cut -c 2-5`
    cputemp=`sensors | grep temp2 |awk ‘{print $2}‘|cut -c 2-5`
    systemp_2=`sensors | grep temp1 |awk ‘{print $2}‘|cut -c 2-3`
    time=`date +%Y%m%d%H%M%S`
    echo "$time     $cputemp        $systemp_1      $systemp_2" >> /usr/share/sensor/gnuplot_temp.data
    gnuplot /usr/share/sensor/gnuplot_temp.script > /var/www/localhost/htdocs/gnuplot_temp.png

    再來寫個gnuplot的script檔:
    gnuplot_temp.script

    ###################################
    #  gnuplot script for CPU & System Temperature.
    http://www.happylinux.tw/
    #  Author:flyfox@gen2.homeip.net
    #  File created:  Fri JUL 16 2005
    #  Last updated:  Sat JUL 17 2005
    ###################################
    set term png
    set timefmt "%Y%m%d%H%M"
    set notime
    set data style lines
    set grid
    set autoscale x
    set autoscale y
    set yrange [30 : 65]
    set mytics 5
    set title "CPU & System Temperature"
    set xlabel "Time"
    set xdata time
    set ylabel "CelsiusDegree"
    set timestamp "Created: %b %d, %Y at %H:%M" top 12,-4.5
            plot    "/usr/share/sensor/gnuplot_temp.data" using 1:2 title ‘CPU Temperature‘,\
                    "/usr/share/sensor/gnuplot_temp.data" using 1:3 title ‘System_2 Temperature‘,\
                    "/usr/share/sensor/gnuplot_temp.data" using 1:4 title ‘System_1 Temperature‘

    CPU & System溫度圖例:


    再秀一張CPU效能的圖例:


    Gnuplot監控圖形


    3.1 gnuplot所繪製的系統監測圖呈現的方法:

  • 獨立網頁:利用簡單的HTML文件即可。
  • 與MRTG整合:將圖表位址加入MRTG的展示頁中。
  • 與phpsysinfo整合:將圖表位址加入phpsysinfo的展示頁中。
  • 其它:其它方法……。

    本站則採取與XOOPS模組化的phpsysinfo來呈現gnuplot所繪製的系統監測圖。
    展示網頁:系統監測圖
    http://www.happylinux.tw/modules/phpsysinfo/

  • 參考資料:
  • Gnuplot 導讀
    Enhanced tellerstats scripts

    迴響

    RSS feed for comments on this post.

    The URI to TrackBack this entry is: http://www.happylinux.tw/modules/wordpress/wp-trackback.php/42

    本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
    打开APP,阅读全文并永久保存 查看更多类似文章
    猜你喜欢
    类似文章
    【热】打开小程序,算一算2024你的财运
    几个常用的Linux监控脚本
    冰点论坛-Linux系统类-【转帖】Linux辅导:一步一步安装服务器监视软件MRTG
    培养这10个习惯,你就离UNIX高手更进一步了
    Linux脚本程序自动修改网卡配置文件中的MAC地址
    aix系统检查脚本
    windows、linux、aix查询端口号被哪个程序占用
    更多类似文章 >>
    生活服务
    热点新闻
    分享 收藏 导长图 关注 下载文章
    绑定账号成功
    后续可登录账号畅享VIP特权!
    如果VIP功能使用有故障,
    可点击这里联系客服!

    联系客服