speedometer 安装使用

speedometer 需要 urwid 模块的支持,安装:
# cd /usr/local/src
# wget -q http://excess.org/urwid/urwid-1.0.1.tar.gz
# tar -zxvvf urwid-1.0.1.tar.gz
# cd urwid-1.0.1
# python setup.py install

running install
running build
running build_py
running build_ext
building 'urwid.str_util' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector –param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fPIC -I/usr/include/python2.4 -c source/str_util.c -o build/temp.linux-x86_64-2.4/source/str_util.o
source/str_util.c:25:20: error: Python.h: No such file or directory
source/str_util.c:88: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
source/str_util.c:100: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
source/str_util.c:121: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token


缺少 dev 文件:
# yum install python-devel.x86_64

CentOS 5.4 默认的 python 版本为 2.4.3,而 speedometer 至少需要 2.6 的版本,先升级下 python 至 2.7:

# yum -y groupinstall 'Development Tools'
# yum -y install openssl-devel* ncurses-devel* zlib*.x86_64</pre>
# yum -y install bzip2 bzip2-devel bzip2-libs
# curl -O http://python.org/ftp/python/2.7/Python-2.7.tgz
# tar xfz Python-2.7.tgz
# cd Python-2.7
# ./configure --prefix=/opt/python2.7 --with-threads --enable-shared
# make -j8
# make install

# export PATH=$PATH:/opt/python2.7/bin
# echo "/opt/python2.7/lib" > /etc/ld.so.conf.d/python27.conf
# ldconfig

# python2.7 -V
Python 2.7

# cd /usr/local/src
# curl -O http://pypi.python.org/packages/2.7/s/setuptoolssetuptools-0.6c11-py2.7.egg
# chmod a+x setuptools-0.6c11-py2.7.egg 
# sh setuptools-0.6c11-py2.7.egg

# curl -O http://pypi.python.org/packages/source/p/pip/pip-1.0.tar.gz
# tar xvfz pip-1.0.tar.gz
# cd pip-1.0
# python2.7 setup.py install

# cd /usr/local/src/
# wget -q http://excess.org/speedometer/speedometer-2.8.tar.gz
# tar -zxvvf speedometer-2.8.tar.gz
# cd speedometer-2.8
# python2.7 setup.py install

测试:
# speedometer -tx eth0 -rx eth0

上面主要是针对 CentOS 的,由于其 python 版本比较老,安装起来比较费劲,Ubuntu 下可以直接通过 apt 安装。

最后有几个关于 speedometer 的应用,最简单的就是通过他来测两点之间了的最大带宽了:
$ cat /dev/zero | nc -l 12345

$ nc IP 12345 > /dev/null
$ speedometer -rx eth0 -tx eth0

其次还可以用来测试硬盘的写速度:
# dd bs=1000000 count=1000 if=/dev/zero of=bigfile & sleep 3
# speedometer bigfile

还可以用来测试文件传输的速度,从一个文件到另一个:
# dd bs=1000000 count=1000 if=/dev/zero of=/tmp/bigfile
# speedometer binfile $((1*1024*1024*1024))
# cp /tmp/bigfile ~

ref:
http://mythinkpond.wordpress.com/2011/12/28/how-to-upgrade-to-python-2-7-on-centos/
http://www.codingwithcody.com/2012/01/python-2-7-on-centos-5-6/
http://toey.tc20.net/2010/08/04/install-python-2-7-gevent-on-centos-5-x86_64/
http://www.pc-freak.net/blog/text-monitoring-of-connection-server-traffic-rx-tx-business-in-ascii-graphs-with-speedometer-easy-monitor-network-traffic-performance/