脚本目的:分析系统资源性能瓶颈
脚本功能:
1、查看CPU利用率与负载(top、vmstat、sar)
2、查看磁盘、Inode利用率与I/O负载(df、iostat、iotop、sar、dstat)
3、查看内存利用率(free、vmstat)
4、查看TCP连接状态(netstat、ss)
5、查看CPU与内存占用最高的10个进程(top、ps)
6、查看网络流量(ifconfig、iftop、iptraf)
脚本说明:通过一些常用的性能分析工具,计算出我们想知道的信息。
脚本如下:
# cat show_sys_info.sh
#!/bin/bash # os_check() { if [ -e /etc/redhat-release ]; then REDHAT=`cat /etc/redhat-release |cut -d' ' -f1` else DEBIAN=`cat /etc/issue |cut -d' ' -f1` fi if [ "$REDHAT" == "CentOS" -o "$REDHAT" == "Red" ]; then P_M=yum elif [ "$DEBIAN" == "Ubuntu" -o "$DEBIAN" == "ubutnu" ]; then P_M=apt-get else Operating system does not support. exit 1 fi } if [ $LOGNAME != root ]; then echo "Please use the root account operation." exit 1 fi if ! which vmstat &>/dev/null; then echo "vmstat command not found, now the install." sleep 1 os_check $P_M install procps -y echo "-----------------------------------------------------------------------" fi if ! which iostat &>/dev/null; then echo "iostat command not found, now the install." sleep 1 os_check $P_M install sysstat -y echo "-----------------------------------------------------------------------" fi while true; do select input in cpu_load disk_load disk_use disk_inode mem_use tcp_status cpu_top10 mem_top10 traffic quit; do case $input in cpu_load) #CPU利用率与负载 echo "---------------------------------------" i=1 while [[ $i -le 3 ]]; do echo -e "