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

#!/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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值