shell脚本实例-shell 分析系统瓶颈脚本

作者简介:
陈志珂(头条号:强扭的瓜不好吃)目前就职于中国最大的安卓应用软件公司,任高级工程师,现在公司任php开发工程师,python开发工程师,高级运维工程师,公众号“铅笔学园”运维内容合作作者之一。**
铅笔学园:IT资源分享|知识分享,做初级程序员的指明灯**

shell脚本实例-shell 分析系统瓶颈脚本
#!/usr/bin/bash

PS3=”Your choice is: [10 for quit]”

#检查是那个系统

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" R E D H A T "==" C e n t O S " − o " REDHAT” == “Red” ]; then

P_M=yum

elif [ “ DEBIAN"=="Ubuntu"o" D E B I A N "==" U b u n t u " − o " DEBIAN” == “ubutnu” ]; then

P_M=apt-get

else

Operating system does not support.

exit 1

fi

}

#判断是否是root用哦过户

if [ $LOGNAME != root ]; then

echo “Please use the root account operation.”

exit 1

fi

#查看cpu工具是否安装

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 usage and load

echo “—————————————”

i=1

while [[ $i -le 3 ]]; do

echo -e “[32m Reference value${i}[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”

i=

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值