banshee/storage-collection/storage/smart/ssh/
disks
The SMART health, temperature, bad sectors and wear of each SATA, SAS or NVMe disk of a Linux by SSH, through a restricted sudo.
by banshee1 installation2 versions
SMART health of the disks, by SSH
Returns, for each SATA, SAS or NVMe disk of a Linux machine, named by its serial number, its SMART health, its path, its temperature, its reallocated, pending and uncorrectable sectors, its power-on time and, for an SSD or an NVMe, its remaining life. A spun-down disk is left asleep, and keeps the health and sectors last read from it, with their age. Eight watches are offered, each one set on the probe. It needs sudo, restricted to the commands below.
Versions
Generic: the JSON of smartctl -j is the same from smartmontools 7.0 on (Debian 11 and later, Ubuntu 20.04 and later, RHEL 8 and later, Fedora, Alpine), so it stays at the common level. A smartctl older than 7.0 knows no -j: the collector stops misconfigured and says so.
How it works
The collector runs, through sudo -n (never a password prompt: a refused sudo stops at once):
/usr/sbin/smartctl --scan-open -j: the disks smartctl can open;/usr/sbin/smartctl -j -n standby -a /dev/<disk>, once per disk namedsdX,sdXY,nvmeNornvmeNN, the names the sudoers line allows; the disk's name goes as a separate, quoted argument.-n standbymakes smartctl stop without waking a disk spun down (standby or sleep).
- A disk is named by its serial number, which follows it when it changes slot or when the kernel renames it at a boot;
devicereturns its path (/dev/sda). A disk that serves no serial number (some USB bridges), or that has never been seen awake, is named by the kernel's name (sda). - The health is
passedorfailed, the overall verdict smartctl reads from the disk: an ATA attribute at or under its threshold, an NVMe critical warning, a SCSI failure prediction all readfailed. It isunknownwhen the disk serves no SMART, or could not be opened (pulled out since the scan, a USB bridge that does not pass SMART through); onlyhealthanddeviceare then returned. powerreadsactiveorstandby. A disk asleep tells nothing, its serial number included: the last reading of the disk awake stands for it. Its serial number names it; itshealth,reallocated,pending,uncorrectableandremaining-lifeare those read then, and raise as they did: a failure never goes out because the disk sleeps.read-agesays, in hours, how old that reading is: 0 for a disk read at this run. The temperature and the power-on time of a disk asleep are not returned. A disk asleep that has never been seen awake readsstandbyinhealth, which raises nothing.- The last reading of each disk is kept in the probe's cache, by path, rewritten at every run for the disks present: it lasts as long as the probe runs, and is lost seven days after its last run, or when its cache is cleared.
- The sectors, by kind of disk: on an ATA disk, the raw values of attributes 5 (
reallocated), 197 (pending) and 198 (uncorrectable); on an NVMe, the media errors (uncorrectable), the data it could not read back; on a SAS disk, the grown defect list (reallocated) and the read errors it could not correct (uncorrectable). A count the disk does not serve is not returned. - The remaining life, in %: 100 minus the percentage used of an NVMe or of a SAS SSD, never under 0; on an ATA SSD, the normalized value of the attribute that gives it, under the names smartmontools gives them (
Wear_Leveling_Countfor Samsung,SSD_Life_Leftfor Kingston and SandForce,Media_Wearout_Indicatorfor Intel,Percent_Lifetime_Remainfor Crucial and Micron). A hard disk returns none. - Nothing is written on the target:
smartctl -a,-n standbyand--scan-openonly read. The sudoers line below allows no other option.
Prerequisites
- An SSH account for monitoring, without write rights (
monitoringbelow; put the account's name in its place). - smartmontools 7.0 or later, and sudo:
apt install smartmontools sudo(Debian, Ubuntu),dnf install smartmontools sudo(Fedora, RHEL),apk add smartmontools sudo(Alpine, which ships without sudo). - The sudoers lines, in
/etc/sudoers.d/banshee-smart, owned by root, mode 0440 (chmod 0440 /etc/sudoers.d/banshee-smart), checked withvisudo -cf /etc/sudoers.d/banshee-smartbefore anything else. They namesmartctlwhere the distribution puts it.
Debian, Ubuntu, Alpine, RHEL, and Fedora up to 41 (/usr/sbin/smartctl):
Cmnd_Alias BANSHEE_SMART = /usr/sbin/smartctl --scan-open -j, /usr/sbin/smartctl -j -n standby -a /dev/sd?, /usr/sbin/smartctl -j -n standby -a /dev/sd??, /usr/sbin/smartctl -j -n standby -a /dev/nvme?, /usr/sbin/smartctl -j -n standby -a /dev/nvme??
monitoring ALL=(root) NOPASSWD: BANSHEE_SMART Fedora 42 and later (/usr/bin/smartctl; /usr/sbin is a link to /usr/bin, so the collector's /usr/sbin/smartctl is the same file, which sudo matches):
Cmnd_Alias BANSHEE_SMART = /usr/bin/smartctl --scan-open -j, /usr/bin/smartctl -j -n standby -a /dev/sd?, /usr/bin/smartctl -j -n standby -a /dev/sd??, /usr/bin/smartctl -j -n standby -a /dev/nvme?, /usr/bin/smartctl -j -n standby -a /dev/nvme??
monitoring ALL=(root) NOPASSWD: BANSHEE_SMART The account may run, as root and without a password, smartctl by its absolute path, with these options in this order, and nothing else: no other option of smartctl (-s, -t, --set, which change a disk's settings or start a self-test), no other command. Only the disk's name varies, and only by ?, one character each: in sudoers a * matches across the arguments (/dev/* would let -j -a /dev/sda -s off through), a ? cannot hold an option. The risk left: ? matches any one character, so /dev/sd?? also lets through a partition (/dev/sda1) or a one-letter extra argument, which smartctl only reads or refuses.
- The fingerprint of the server's host key, set in
protocol:ssh:fingerprint(not needed when the Security settings trust the first SSH fingerprint presented).
Outputs
| Name | Label | Unit | Per instance |
|---|---|---|---|
health | SMART health | — | yes, per disk |
device | Device | — | yes, per disk |
power | Power state | — | yes, per disk |
read-age | Age of the SMART reading | h | yes, per disk |
temperature | Temperature | °C | yes, per disk |
reallocated | Reallocated sectors | — | yes, per disk |
pending | Pending sectors | — | yes, per disk |
uncorrectable | Uncorrectable sectors | — | yes, per disk |
power-on | Power-on time | h | yes, per disk |
remaining-life | Remaining life | % | yes, per disk |
Watches
| Name | Title | Kind | Defaults | Checked by default |
|---|---|---|---|---|
failed | SMART health failed | state to avoid, on health | critical on failed | yes |
unknown | SMART health unknown | state to avoid, on health | warning on unknown | yes |
hot | High temperature | above a threshold, on temperature | warning above 55 °C, critical above 60 °C, for 3 runs | yes |
reallocated | New reallocated sectors | increase, on reallocated | warning beyond 0 in 7 d | yes |
pending | Pending sectors | above a threshold, on pending | warning above 0 | yes |
uncorrectable | New uncorrectable sectors | increase, on uncorrectable | critical beyond 0 in 7 d | yes |
worn | Disk worn out | below a threshold, on remaining-life | warning below 10 %, critical below 3 % | yes |
missing | Disk missing | expected instances, on health | no disk named: it raises nothing until names are set on the probe | no |
reallocatedanduncorrectableraise on a rise, not on a count: a disk that has carried a few reallocated sectors for years stays green, a new one raises for a week. A pending sector is a sector the disk could not read and waits to rewrite: it raises as long as there is one.- The temperature thresholds are those of a hard disk; an NVMe often runs warmer, and its thresholds are raised on the probe.
Limits
- A
sudothat refuses (no sudoers line, a line that does not match, a password asked), a missingsmartctl, or a smartctl older than 7.0, stops the collectormisconfigured, with what sudo or smartctl said. So does a machine with no disk the sudoers line allows. - Only disks named
sdX,sdXY,nvmeNandnvmeNNare read: the names of another system (FreeBSD'sada0,da0) are left out. - Hardware RAID is not this collector's: the disks behind a RAID controller (
/dev/bus/0 -d megaraid,N,cciss,areca) are hidden from the system and left out; the controller's own tools or its management card see them. - While a disk sleeps, its health and sectors are those of its last reading,
read-agehours old: a new failure shows only when it wakes. A disk swapped while asleep is shown with the reading of the disk it replaced until it is read awake. - The readings kept fit in the probe's cache, 16,384 characters, about a hundred disks: beyond, the collector stops
misconfigured. - A disk seen through two paths (multipath) is read once, by the first path that names it.
- Whether
-n standbyleaves an NVMe asleep depends on the version of smartmontools; an NVMe is read as if awake when it does not. - One SSH command per disk: a machine with many disks takes as many round trips.
- The raw value of attribute 5, 197 or 198 is read as a count, as most makers write it; a maker that packs other figures in it would show a wrong count.
- Not checked against a disk: the fields are those smartmontools documents for its JSON output, and a sleeping disk is recognised by the words smartctl writes for it (
STANDBY mode,SLEEP mode); the sudoers lines are not checked against a sudo.