您的位置:首页 > 其它

test-definitions/blob/master/auto-test/dstat/dstat.sh

2018-01-19 08:57 330 查看
#!/bin/sh
#回显执行的命令和参数
set -x
#cd到目录执行脚本,然后通过cd -返回到当前目录
cd ../../utils
. ./sys_info.sh
cd -
#检查是否是root用户
# Test user id
if [ `whoami` != 'root' ] ; then
echo "You must be the superuser to run this script" >&2
exit 1
fi
#根据不同发行版安装不同的包
case $distro in
"debian|ubuntu")
apt-get install dstat -y
print_info $? install-dstat
;;
"centos")
yum install dstat -y
print_info $? install-dstat

esac

#输出默认监控,报表 输出时间间隔为3s,输出10个结果
dstat 3 10  2>&1 | tee dstat.log
print_info $? dstat

#查看内存占用情况
dstat -g -l -m -s --top-mem 3 10 2>&1 | tee -a dstat.log
print_info $? dstat-g

#显示一些关于cpu资源损耗的数据
dstat -c -y -l --proc-count --top-cpu 3 10 2>&1 | tee -a dstat.log
print_info $? dstat-c

#查看当前占用I/O,cpu,内存等最高的进程信息
dstat --top-mem --top-io --top-cpu 3 10 2>&1 | tee -a dstat.log
print_info $? dstat-top

#查看某个cpu状态信息
dstat -c 0,1 3 10 2>&1 | tee -a dstat.log
print_info $? dstat-c-01

#查看系统的磁盘的读写数据大小
dstat -d 3 10 2>&1 | tee -a dstat.log

#查看系统网络状态
dstat -n 3 10 2>&1 | tee -a dstat.log
print_info $? dstat-n

#查看系统负载情况
dstat -l 3 10 2>&1 | tee -a dstat.log
print_info $? dstat-l

#查看系统进程信息
dstat -p 3 10 2>&1 | tee -a dstat.log
print_info $? dstat-p

#查看系统tcp,udp端口情况
dstat --socket 3 10 2>&1 | tee -a dstat.log
print_info $? dstat-socket

#查看I/o请求情况
dstat -r 3 10 2>&1 | tee -a dstat.log
print_info $? dstat-r
#由于前面执行了很多次dstat ,因此此时可能有多个dstat 进程存在,这个
#找到所有的dstat进程的个数
count=`ps -aux | grep dstat | wc -l`
if [ $count -gt 0 ]; then
#通过pidof 根据进程name得到进程pid,然后通过kill 杀掉这些进程。这里的9是强制终止进程
kill -9 $(pidof dstat)
print_info $? kill-dstat
fi
测试完成后,根据发行版删除dstat包
case $distro in
"ubuntu|debian")
apt-get remove dstat -y
print_info $? remove-dstat
;;
"centos")
yum remove dstat -y
print_info $? remove-dstat
;;
esac
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: