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
效果展示