Browse Source

add script for getting disk size and lifetime in a nice table...

This depends upon drives being labeled, which I do..
main
John-Mark Gurney 4 years ago
parent
commit
9c0d636038
1 changed files with 60 additions and 0 deletions
  1. +60
    -0
      diskstat

+ 60
- 0
diskstat View File

@@ -0,0 +1,60 @@
#!/bin/sh

# | egrep $(zpool list -v ztank | grep label | awk 'BEGIN { j="" } { printf "%s%s", j, substr($1, 7, length($1) - 10); j="|" } END { print "" }' )
# state=0 parsing diskinfo
# state=1 parsing glabel
(diskinfo /dev/ada*[0-9]; glabel status) | awk -v state=0 '
BEGIN {
}

function printdiskinfo(lblname, devname) {
cmd = "smartctl -a /dev/" devname " | egrep '"'"'Device Model|Power_On_Hours'"'"'"
cmd | getline
$1 = ""
$2 = ""
model = $0
cmd | getline
hours = $10
close(cmd)

years = sprintf("%.4g", ( hours / 24. / 365 ))
print lblname "\t->\t" devname "\t->\t" disksize[devname] " TB\t->\t" years "\t" model
delete disksize[devname]
}

$0 ~ "Name" {
state=1
}

state == 0 {
ncomp = split($1, comp, "/")
basecomp = comp[ncomp]
if (basecomp !~ "p") {
tb = int($3 / 1000 / 1000 / 1000 / 1000)
if (tb != 0)
disksize[basecomp] = tb
if (tb == 0)
disksize[basecomp] = sprintf("%.2f", int($3 / 1000 / 1000 / 1000) / 1000)
}
}

state == 1 {
ncomp = split($1, comp, "/")
basecomp = comp[ncomp]
devname = $3

if (comp[1] != "label") {
next
}

printdiskinfo(basecomp, devname)

}

END {
for (i in disksize) {
printdiskinfo("xxx", i)
}
}
' - | sort
echo

Loading…
Cancel
Save