我想随着时间的推移开始存储 SMART 数据,并根据磁盘 ID/序列号查看任何趋势。例如,可以让我每天从磁盘中获取一次智能信息并将其放入数据库中。Linux 中是否已经有用于此的工具,还是我必须自己推出?
“自己动手”很容易。smartctl -A drive-specifier
通过 AWK 脚本每天(以 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
Run Code Online (Sandbox Code Playgroud)
AWK "NR>=8 && NR<=21" 挑选出正确的行号,print 语句挑选出合适的列;所述tr
移除新线; sed
修复了 SMART 属性问题并添加了一个换行符。
因此,每天有一条记录以日期格式写入 CSV 日志文件,[属性 ID、属性名称、属性值]*N 格式。
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"
Run Code Online (Sandbox Code Playgroud)
我相信有更好的脚本可用!
归档时间: |
|
查看次数: |
845 次 |
最近记录: |