Linux环境检查测试

Linux环境检查测试脚本

#!/bin/bash
#Author: flf

[ $(id -u) -gt 0 ] && echo "Execute this script as the root user !" && exit 1
  
io_read(){
 echo -e "\033[1;33mStart testing the disk read speed...\033[0m"
 disks=$(lsblk |grep disk|awk '{print $1}')
 for disk in $disks;do
     hdparm -tT /dev/${disk}
 done
}

io_write(){
  echo -e "\033[1;33mStart testing current path write speed...\033[0m"
  dd if=/dev/zero of=./test.dbf bs=4k count=2000000 conv=fsync
  echo -e "\033[1;33mStart testing current path read speed...\033[0m"
  dd if=./test.dbf bs=4k | dd of=/dev/null iflag=direct
  rm -f ./test.dbf
}

echo -e "\033[1;32m-------------------------------System info-----------------------------------\033[0m"
echo -e "Hostname:\t\t"`hostname`
echo -e "uptime:\t\t\t"`uptime | awk '{print $3,$4}' | sed 's/,//'`
echo -e "Product Name:\t\t"`cat /sys/class/dmi/id/product_name`
echo -e "Version:\t\t"`cat /etc/os-release | grep VERSION= | awk -F "=" '{print $2}' | tr -d "\""`
echo -e "Machine Type:\t\t"`vserver=$(lscpu | grep Hypervisor | wc -l); if [ $vserver -gt 0 ]; then echo "VM"; else echo "Physical"; fi`
echo -e "Operating System:\t"`hostnamectl | grep "Operating System" | cut -d ' ' -f5-`
echo -e "Kernel:\t\t\t"`uname -r`
echo -e "Architecture:\t\t"`arch`
echo -e "Processor Name:\t\t"`awk -F':' '/^model name/ {print $2}' /proc/cpuinfo | uniq | sed -e 's/^[ \t]*//'`
echo -e "Active User:\t\t"`w | cut -d ' ' -f1 | grep -v USER | xargs -n1`
echo -e "System Main IP:\t\t"`hostname -I`
echo -e "docker version:\t\t"`docker -v | awk -F ',' '{print $1}'`
echo ""
echo -e "\033[1;32m-------------------------------CPU info--------------------------------------\033[0m"
echo -e "CPU Usage:\t"`cat /proc/stat | awk '/cpu/{printf("%.2f%s\n"), ($2+$4)*100/($2+$4+$5), "%"}' |  awk '{print $0}' | head -1`
echo ""
lscpu | sed -n 4,9p
echo ""
echo -e "\033[1;32m-------------------------------Memory info-----------------------------------\033[0m"
echo -e "Memory Usage:\t"`free | awk '/Mem/{printf("%.2f%s"), $3/$2*100, "%"}'`
echo -e "Swap Usage:\t"`free | awk '/Swap/{printf("%.2f%s"), $3/$2*100, "%"}'`
echo ""
free -h
echo ""
echo -e "\033[1;32m-------------------------------Network speed---------------------------------\033[0m"
#route -n | grep ^0.0.0.0 | awk '{print $8}'
nics=$(route -n | grep ^0.0.0.0 | awk '{print $8}')
  for nic in $nics;do
       ethtool $nic | grep Speed | tr -d '\t'
  done
echo ""
echo -e "\033[1;32m-------------------------------Disk Usage >80%-------------------------------\033[0m"
df -Ph | sed s/%//g | awk '{ if($5 > 80) print $0;}'
echo ""
echo -e "\033[1;32m-------------------------------IO read/write speed---------------------------\033[0m"
 io_read
echo ""
 io_write

效果展示
在这里插入图片描述
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值