#!/bin/bash
function get_pcie() {
pcie=""
pcie_result="successful"
for NVME in `lspci | grep -i non-V | awk '{print $1}'`
do
s_pcie=`lspci -s $NVME -vvv | grep LnkSta: | awk '{print $3}'`
if [ ! -n "$pcie" ]; then
pcie=$s_pcie
else
if [ $pcie != $s_pcie ]; then
pcie_result="failed"
break
fi
fi
done
if [ $pcie_result == 'successful' ]; then
echo $pcie
else
echo -e "\033[31m 设备速率标准不统一,请人为判断磁盘性能 \033[0m"
fi
}
r_pcie=`get_pcie`
echo -e "\033[32m 【开始NVME性能测试】($r_pcie) \033[0m"
echo "【开始NVME性能测试】($r_pcie)" > /root/fio.log
get_system_disk=`lsblk | grep /boot$ | awk '{print $1}' | awk -F 'nvme' '{print $2}' | awk -F 'p' '{print $1}'`
if [ $get_system_disk ]; then
system_disk="nvme"$get_system_disk
else
system_disk="None"
fi
for NVME in `nvme list | grep nvme | grep -v $system_disk | awk '{print $1}'`
do
# 磁盘基础信息
echo -e "\033[32m 磁盘: $NVME \033[0m"
nvme_hours_info=`smartctl -A $NVME | grep "Power On Hours" | awk '{print $4}'`
nvme_read_info=`smartctl -A $NVME | grep "Data Units Read" | awk -F "[" '{print $2}' | awk -F "]" '{print $1}'`
nvme_write_info=`smartctl -A $NVME | grep "Data Units Written" | awk -F "[" '{print $2}' | awk -F "]" '{print $1}'`
echo -e "\033[32m --磁盘信息: 已持续使用 $nvme_hours_info 小时; 已读数据 $nvme_read_info; 已写数据 $nvme_write_info \033[0m"
echo "磁盘: $NVME" >> /root/fio.log
echo "磁盘信息: 已持续使用 $nvme_hours_info 小时; 已读数据 $nvme_read_info; 已写数据 $nvme_write_info" >> /root/fio.log
# 4K随机读
echo -e "\033[32m ----测试项: 4K随机读 \033[0m"
r_r_info=`fio -name=Rand_Read_IOPS_Test -group_reporting -direct=1 -iodepth=128 -rw=randread -ioengine=libaio -refill_buffers -norandommap -randrepeat=0 -bs=4k -size=10G -numjobs=1 -runtime=300 -filename=$NVME | grep IOPS=`
echo $r_r_info
r_r_result=`echo $r_r_info | awk '{print $2}' | awk -F "," {'print $1'}`
echo "----测试项: 4K随机读: $r_r_result" >> /root/fio.log
# 4K随机写
echo -e "\033[32m ----测试项: 4K随机写 \033[0m"
r_w_info=`fio -name=Rand_Write_IOPS_Test -group_reporting -direct=1 -iodepth=128 -rw=randwrite -ioengine=libaio -refill_buffers -norandommap -randrepeat=0 -bs=4k -size=10G -numjobs=1 -runtime=600 -allow_mounted_write=1 -filename=$NVME | grep IOPS=`
echo $r_w_info
r_w_result=`echo $r_w_info | awk '{print $2}' | awk -F "," {'print $1'}`
echo "----测试项: 4K随机写: $r_w_result" >> /root/fio.log
# 128K顺序写
echo -e "\033[32m ----测试项: 128K顺序写 \033[0m"
s_w_info=`fio -name=Seq_Write_IOPS_Test -group_reporting -direct=1 -iodepth=128 -rw=write -ioengine=libaio -refill_buffers -norandommap -randrepeat=0 -bs=128k -size=10G -numjobs=1 -runtime=300 -allow_mounted_write=1 -filename=$NVME | grep WRITE`
echo $s_w_info
s_w_result=`echo $s_w_info | awk '{print $2}' | awk -F "=" {'print $2'}`
echo "----测试项: 128K顺序写: $s_w_result" >> /root/fio.log
# 128K顺序读
echo -e "\033[32m ----测试项: 128K顺序读 \033[0m"
s_r_info=`fio -name=Seq_Read_IOPS_Test -group_reporting -direct=1 -iodepth=128 -rw=read -ioengine=libaio -refill_buffers -norandommap -randrepeat=0 -bs=128k -size=10G -numjobs=1 -runtime=300 -filename=$NVME | grep READ`
echo $s_r_info
s_r_result=`echo $s_r_info | awk '{print $2}' | awk -F "=" {'print $2'}`
echo "----测试项: 128K顺序读: $s_r_result" >> /root/fio.log
done
echo -e "\033[32m 【完成NVME性能测试!!!】 \033[0m"