功能
我們經(jīng)常使用vmstat是不是就下面這個(gè)樣子的:
$ vmstat 1
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
3 0 43652 2742600 453820 2829164 0 0 1 10 0 0 6 1 93 0
1 0 43652 2742784 453820 2829164 0 0 0 0 3106 5701 11 1 87 0
0 0 43652 2742908 453820 2829164 0 0 0 0 3898 6703 11 2 87 0
1 0 43652 2743672 453820 2829164 0 0 0 32 3844 6708 11 2 87 0
2 0 43652 2743980 453820 2829164 0 0 0 80 4130 7164 11 2 87 0
web wmstat可以把上面的數(shù)據(jù)在網(wǎng)頁(yè)上動(dòng)態(tài)圖形顯示出來(lái),效果如下:

screenshot.png
項(xiàng)目
這個(gè)項(xiàng)目的地址如下:
https://github.com/joewalnes/web-vmstats
原理
這個(gè)小程序使用websocket協(xié)議,使用的websocket Server是websocketd,通過(guò)websocket接收vmstat程序員的輸出,然后使用SmoothieCharts來(lái)畫(huà)圖。
如果不了解websocketed,可以參考項(xiàng)目地址或是我之前寫的"WebSocket和websocketd"
使用
下載程序,然后運(yùn)行
./run
前提已經(jīng)說(shuō)過(guò)了,你需要先安裝websocketd。
查看run文件,內(nèi)容如下:
#!/bin/sh
# Download websocketd for your platform from
# https://github.com/joewalnes/websocketd/wiki/Download-and-install
./websocketd --port=9231 --staticdir=web /usr/bin/vmstat -n 1