我想开始随着时间的推移存储 SMART 数据,并根据磁盘 ID/序列号查看任何趋势。例如,可以让我每天从磁盘获取一次智能信息并将其放入数据库中。 Linux 中是否已经有这样的工具,还是我必须自己开发一个工具?
答案1
答案2
“自己动手”很容易。每天通过 AWK 脚本运行smartctl -A drive-specifier
(以 root 身份),并将输出输出到文件中。
gnuplot
适合绘制该文件的图表。
对此稍加扩展,举个例子:-
- 放置一个条目来运行以下脚本
/etc/cron.daily
#!/bin/sh
# SMART DISK PROCESSING
# =====================
tmpfile=$(mktemp -q)
today=$(date -u +%d-%m-%Y)
smartctl -A /dev/disk/by-id/ata-Samsung_SSD_870_QVO_1TB_S5SVNG0NB22319L > $tmpfile
# Output log as a single line - note "Unknown_Attribute" is "POR_Recovery_Count" [unexpected shutdown]
echo -n $today ', ' >> /var/log/disk-monitor.d/sdb-errors.csv
awk 'NR>=8 && NR<=21 {print $1,",",$2,",",$10,",";}' $tmpfile | tr -d '\n' | sed 's/Unknown_Attribute/POR_Recovery_Count/;s/\,$/\n/' >> /var/log/disk-monitor.d/sdb-errors.csv
exit 0
AWK "NR>=8 && NR<=21" 挑选出正确的行号, print 语句挑选出适当的列;删除tr
换行符;sed
修复了 SMART 属性问题并添加了一个换行符。
这样,每天都会以日期 [属性 ID、属性名称、属性值]*N 格式将一条记录写入 CSV 日志文件。
07-06-2021 , 5 , Reallocated_Sector_Ct , 0 ,9 , Power_On_Hours , 2900 , ...
- 我选择根据需要绘制选定的值[理想情况下为零的值]...我使用的脚本
gnuplot script-name
如下,
set title "SDA Errors which should be ZERO"
set xdata time
set timefmt "%d-%m-%Y"
set format x "%d/%m"
set datafile separator ","
set colorsequence default
set ytics 2 nomirror tc lt 2
set ylabel 'POR' tc lt 2
set yrange [0:30<*]
set y2tics 1 nomirror tc lt 1
set y2label 'Errors' tc lt 1
set y2range [-1:10]
set key left top
set grid ytics lt 0 lw 1 lc rgb "#bbbbbb"
set grid xtics lt 0 lw 1 lc rgb "#bbbbbb"
plot "/var/log/disk-monitor.d/sda-errors.csv" using 1:4 title "Reallocated Sector Count" with lines axes x1y2, '' using 1:13 title "Wear Levelling Count" with lines axes x1y2, '' using 1:16 title "Used Rsvd Blk Cnt Total" with lines axes x1y2, '' using 1:19 title "Program Fail Cnt Total" with lines axes x1y2, '' using 1:22 title "Erase Fail Count Total" with lines axes x1y2, '' using 1:25 title "Runtime Bad Block" with lines axes x1y2, '' using 1:28 title "Reported Uncorrect" with lines axes x1y2, '' using 1:34 title "Hardware ECC Recovered" with lines dt 3 axes x1y2, '' using 1:40 title "POR Recovery Count" with lines dt 1 linetype rgb "green" axes x1y1
pause -1 "Hit any key to continue"
我确信有更好的脚本可用!