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=
while [[ $i -le ]]; do
echo -e "\033[32m 参考值${i}\033[0m"
UTIL=`vmstat |awk '{if(NR==3)print 100-$15"%"}'`
USER=`vmstat |awk '{if(NR==3)print $13"%"}'`
SYS=`vmstat |awk '{if(NR==3)print $14"%"}'`
IOWAIT=`vmstat |awk '{if(NR==3)print $16"%"}'`
echo "Util: $UTIL"
echo "User use: $USER"
echo "System use: $SYS"
echo "I/O wait: $IOWAIT"
let i++
sleep
done
echo "---------------------------------------"
break
;;
disk_load)
#硬盘I/O负载
echo "---------------------------------------"
i=
while [[ $i -le ]]; do
echo -e "\033[32m 参考值${i}\033[0m"
UTIL=`iostat -x -k |awk '/^[v|s]/{OFS=": ";print $1,$NF"%"}'`
READ=`iostat -x -k |awk '/^[v|s]/{OFS=": ";print $1,$6"KB"}'`
WRITE=`iostat -x -k |awk '/^[v|s]/{OFS=": ";print $1,$7"KB"}'`
IOWAIT=`vmstat |awk '{if(NR==3)print $16"%"}'`
echo -e "Util:"
echo -e "${UTIL}"
echo -e "I/O Wait: $IOWAIT"
echo -e "Read/s:\n$READ"
echo -e "Write/s:\n$WRITE"
i=$(($i+))
sleep
done
echo "---------------------------------------"
break
;;
disk_use)
#硬盘利用率
DISK_LOG=/tmp/disk_use.tmp
DISK_TOTAL=`fdisk -l |awk '/^Disk.*bytes/ && /\/dev/{printf $2" ";printf "%d",$3;print "GB"}'`
USE_RATE=`df -h |awk '/^\/dev/{print int($5)}'`
for i in $USE_RATE; do
if [ $i -gt ];then
PART=`df -h |awk '{if(int($5)=='''$i''') print $6}'`
echo "$PART = ${i}%" >> $DISK_LOG
fi
done
echo "---------------------------------------"
echo -e "Disk total:\n${DISK_TOTAL}"
if [ -f $DISK_LOG ]; then
echo "---------------------------------------"
cat $DISK_LOG
echo "---------------------------------------"
rm -f $DISK_LOG
else
echo "---------------------------------------"
echo "Disk use rate no than 90% of the partition."
echo "---------------------------------------"
fi
break
;;
disk_inode)
#硬盘inode利用率
INODE_LOG=/tmp/inode_use.tmp
INODE_USE=`df -i |awk '/^\/dev/{print int($5)}'`
for i in $INODE_USE; do
if [ $i -gt ]; then
PART=`df -h |awk '{if(int($5)=='''$i''') print $6}'`
echo "$PART = ${i}%" >> $INODE_LOG
fi
done
if [ -f $INODE_LOG ]; then
echo "---------------------------------------"
cat $INODE_LOG
rm -f $INODE_LOG
else
echo "---------------------------------------"
echo "Inode use rate no than 90% of the partition."
echo "---------------------------------------"
fi
break
;;
mem_use)
#内存利用率
echo "---------------------------------------"
MEM_TOTAL=`free -m |awk '{if(NR==2)printf "%.1f",$2/1024}END{print "G"}'`
USE=`free -m |awk '{if(NR==2) printf "%.1f",$3/1024}END{print "G"}'`
FREE=`free -m |awk '{if(NR==2) printf "%.1f",$4/1024}END{print "G"}'`
CACHE=`free -m |awk '{if(NR==2) printf "%.1f",$6/1024}END{print "G"}'`
echo -e "Total: $MEM_TOTAL"
echo -e "Use: $USE"
echo -e "Free: $FREE"
echo -e "Cache: $CACHE"
echo "---------------------------------------"
break
;;
tcp_status)
#网络连接状态
echo "---------------------------------------"
COUNT=`ss -ant |awk '!/State/{status[$1]++}END{for(i in status) print i,status[i]}'`
echo -e "TCP connection status:\n$COUNT"
echo "---------------------------------------"
;;
cpu_top10)
#占用CPU高的前10个进程
echo "---------------------------------------"
CPU_LOG=/tmp/cpu_top.tmp
i=
while [[ $i -le ]]; do
#ps aux |awk '{if($3>0.1)print "CPU: "$3"% -->",$11,$12,$13,$14,$15,$16,"(PID:"$2")" |"sort -k2 -nr |head -n 10"}' > $CPU_LOG
ps aux |awk '{if($3>0.1){{printf "PID: "$2" CPU: "$3"% --> "}for(i=11;i<=NF;i++)if(i==NF)printf $i"\n";else printf $i}}' |sort -k4 -nr |head - > $CPU_LOG
#循环从11列(进程名)开始打印,如果i等于最后一行,就打印i的列并换行,否则就打印i的列
if [[ -n `cat $CPU_LOG` ]]; then
echo -e "\033[32m 参考值${i}\033[0m"
cat $CPU_LOG
> $CPU_LOG
else
echo "No process using the CPU."
break
fi
let i++
sleep
done
echo "---------------------------------------"
break
;;
mem_top10)
#占用内存高的前10个进程
echo "---------------------------------------"
MEM_LOG=/tmp/mem_top.tmp
i=
while [[ $i -le ]]; do
#ps aux |awk '{if($4>0.1)print "Memory: "$4"% -->",$11,$12,$13,$14,$15,$16,"(PID:"$2")" |"sort -k2 -nr |head -n 10"}' > $MEM_LOG
ps aux |awk '{if($4>0.1){{printf "PID: "$2" Memory: "$4"% --> "}for(i=11;i<=NF;i++)if(i==NF)printf $i"\n";else printf $i}}' |sort -k4 -nr |head - > $MEM_LOG
if [[ -n `cat $MEM_LOG` ]]; then
echo -e "\033[32m 参考值${i}\033[0m"
cat $MEM_LOG
> $MEM_LOG
else
echo "No process using the Memory."
break
fi
i=$(($i+))
sleep
done
echo "---------------------------------------"
break
;;
traffic)
#查看网络流量
while true; do
read -p "Please enter the network card name(eth[0-9] or em[0-9] or team[0-9]): " eth
if [ `ifconfig |grep -c "\<$eth\>"` -eq ]; then
break
else
echo "Input format error or Don't have the card name, please input again."
fi
done
echo "---------------------------------------"
echo -e " In ------ Out"
i=
while [[ $i -le ]]; do
#CentOS6和CentOS7 ifconfig输出进出流量信息位置不同:
#CentOS6中RX与TX行号等于8
#CentOS7中RX行号是5,TX行号是7 OLD_IN=`ifconfig $eth |awk -F'[: ]+' '/bytes/{if(NR==8)print $4;else if(NR==5)print $6}'`
OLD_OUT=`ifconfig $eth |awk -F'[: ]+' '/bytes/{if(NR==8)print $9;else if(NR==7)print $6}'`
sleep
NEW_IN=`ifconfig $eth |awk -F'[: ]+' '/bytes/{if(NR==8)print $4;else if(NR==5)print $6}'`
NEW_OUT=`ifconfig $eth |awk -F'[: ]+' '/bytes/{if(NR==8)print $9;else if(NR==7)print $6}'` IN=`awk 'BEGIN{printf "%.1f\n",'$((${NEW_IN}-${OLD_IN}))'/1024/128}'`
OUT=`awk 'BEGIN{printf "%.1f\n",'$((${NEW_OUT}-${OLD_OUT}))'/1024/128}'`
echo "${IN}MB/s ${OUT}MB/s" i=$(($i+))
sleep
done
echo "---------------------------------------"
break
;;
quit)
exit
;;
*)
echo "---------------------------------------"
echo "Please enter the number."
echo "---------------------------------------"
break
;;

whil的更多相关文章

  1. day0203 (whil else)

    count = 0while count <= 5 : count += 1 if count == 3:break print("Loop",count) else: pr ...

  2. Linux shell循环

    条件测试 格式 test condition 或 [ condition ] 使用方括号时,要注意在条件两边加上空格,如果有操作符,运算符之间也必须有空格 测试状态:测试的结果可以用$?的值来判断,0 ...

  3. ACM: HDU 2544 最短路-Dijkstra算法

    HDU 2544最短路 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Descrip ...

  4. Mysql函数集合

    Mysql提供了很多函数 提供的常用函数集合 一.数学函数 ABS(x) 返回x的绝对值 BIN(x) 返回x的二进制(OCT返回八进制,HEX返回十六进制) CEILING(x) 返回大于x的最小整 ...

  5. 《笨办法学Python》

    习题一 第一个程序 print "Hello World!" print "Hello Evilxr" print "I like typing th ...

  6. Ubuntu 14.04 – How to install xrdp in Ubuntu 14.04

    http://c-nergy.be/blog/?p=5305 Hello World, Ubuntu 14.04 has been released on April 17th 2014 and we ...

  7. python-打印简单公司员工信息表

    python-打印简单公司员工信息表 要求,输入name不为空,输入次数最多3次,3次后跳出程序: 知识点: raw_input str转int whil if elif else continue ...

  8. Python 学习日记(第二周)

    从这周开始我就正式学习Python 语言了.以后每周都会有一篇有关于学习Python的见闻与大家分享! Python的安装 学习的第一步首先要有一个运行的环境.所以接下来介绍一下安装的步骤. 通过Py ...

  9. HNCU1741:算法3-2:行编辑程序

    http://hncu.acmclub.com/index.php?app=problem_title&id=111&problem_id=1741 题目描述 一个简单的行编辑程序的功 ...

随机推荐

  1. iris:get json

    package main import( "github.com/kataras/iris" "github.com/kataras/iris/middleware/lo ...

  2. 关于jetbrains系列产品2018.1.5以后的使用(crack)方法

    产品请一律官网下载:https://www.jetbrains.com/ 我这里以JetBrains GoLand 2018.2.1为例说明下非付费的使用方法(若资金允许,请点击https://www ...

  3. Running cells requires Jupyter notebooks to be installed

    /******************************************************************************* * Running cells req ...

  4. hyperscan简单学习(2)

    对hyperscan官方的前两个example进行编译和运行. 支持单个和多个正则编译.并行匹配规则,性能高. 对块模式和流模式使用: 示例pcapscan: http://www.cnblogs.c ...

  5. install kali on my x200

    1 下载kali镜像,选择tsinghua tuna mirror https://mirrors.tuna.tsinghua.edu.cn/kali-images/current/ 选择light版 ...

  6. 在LINUX(Ubuntu 18.04.x、CentOS)下配置MySQL8.0.x

    安装教程:Installing MySQL on Unix/Linux Using Generic Binaries MySQL下载链接:https://dev.mysql.com/downloads ...

  7. ajango--orm操作

    一 必知必会13条: 返回对象列表的: 1.all() :查所有 2.filter() :查一行 3.exclude():排除(里面可以写条件,意思除了这个条件的所有) 4.order_by():默认 ...

  8. useful urls

    数据挖掘技术: http://ddl.escience.cn/f/IwoF?rid=8188575 李航 统计学习方法: http://ddl.escience.cn/f/Iwn0

  9. sdk(输入驱动物体 驱动属性 被驱动物体 被驱动属性 驱动数值 一键搞定驱动),当你的目标体很多展开会卡的时候使用这个

    import  maya.cmds  as  mc def   sdksomething( sdk_obj="",                    sdkAttr=" ...

  10. The 19th Zhejiang University Programming Contest Sponsored by TuSimple (Mirror)

    http://acm.zju.edu.cn/onlinejudge/showContestProblems.do?contestId=391 A     Thanks, TuSimple! Time ...