本文共 1713 字,大约阅读时间需要 5 分钟。
#!/bin/sh#回显执行的命令和参数set -x#cd到目录执行脚本,然后通过cd -返回到当前目录cd ../../utils . ./sys_info.shcd -#检查是否是root用户# Test user idif [ `whoami` != 'root' ] ; then echo "You must be the superuser to run this script" >&2 exit 1fi#根据不同发行版安装不同的包case $distro in "debian|ubuntu") apt-get install dstat -y print_info $? install-dstat ;; "centos") yum install dstat -y print_info $? install-dstatesac#输出默认监控,报表 输出时间间隔为3s,输出10个结果dstat 3 10 2>&1 | tee dstat.logprint_info $? dstat#查看内存占用情况dstat -g -l -m -s --top-mem 3 10 2>&1 | tee -a dstat.logprint_info $? dstat-g#显示一些关于cpu资源损耗的数据dstat -c -y -l --proc-count --top-cpu 3 10 2>&1 | tee -a dstat.logprint_info $? dstat-c#查看当前占用I/O,cpu,内存等最高的进程信息dstat --top-mem --top-io --top-cpu 3 10 2>&1 | tee -a dstat.logprint_info $? dstat-top#查看某个cpu状态信息dstat -c 0,1 3 10 2>&1 | tee -a dstat.logprint_info $? dstat-c-01#查看系统的磁盘的读写数据大小dstat -d 3 10 2>&1 | tee -a dstat.log#查看系统网络状态dstat -n 3 10 2>&1 | tee -a dstat.logprint_info $? dstat-n#查看系统负载情况dstat -l 3 10 2>&1 | tee -a dstat.logprint_info $? dstat-l#查看系统进程信息dstat -p 3 10 2>&1 | tee -a dstat.logprint_info $? dstat-p#查看系统tcp,udp端口情况dstat --socket 3 10 2>&1 | tee -a dstat.logprint_info $? dstat-socket#查看I/o请求情况dstat -r 3 10 2>&1 | tee -a dstat.logprint_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-dstatfi测试完成后,根据发行版删除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
转载地址:http://oznmi.baihongyu.com/