Scripts to report SMART, ZPool and UPS status, HDD/CPU T°, HDD identification and backup the config

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
@hugovsky Yes, you need to add a if() to suppress the devices who doesn't have "da" in their name. I'm just back from vacation and ultra busy so I can't do that for now but I'm sure you'll find out ;)
 
Last edited:

Ruff.Hi

Patron
Joined
Apr 21, 2015
Messages
271
Don't know if someone noticed but, if using

Code:
drives=`sysctl -n kern.disks | awk '{for (i=NF; i!=0 ; i--) print $i }'`


You get also cdrom and usb drives. Is there a way to only select hardrives?

I asked this question to and I was struggling to find a way of doing it. Biduleohm left it with me as homework and I didn't get very far. I asked a question about motherboard temps and was provided with a hint to search in the output from 'sysctl -a'. While looking in that output for motherboard temperatures (not there ... btw), I found that it reports on the sizes of the drives it finds. With that bit of info, I wrote a script to search through the list of possible HDDs and only build a string if the HDD was over a certain size (I selected 25Gb). This process leaves out my thumbdrives and only reports my 4TB drives.

Code:
#!/bin/sh
PossibleHDDs=`sysctl -n kern.disks | awk '{for (i=NF; i!=0 ; i--) print $i }'`

drives=""

for SingleHDD in $PossibleHDDs
do
   SearchString="0 DISK "${SingleHDD}

###   echo "SingleHDD "$SingleHDD

   HDDsize=`sysctl -a | grep "${SearchString}" | cut -d' ' -f 4`

   ### the size code can return the HDD itself and not the size
   ### need 5th value in this case
   if [ $HDDsize = ${SingleHDD} ] ; then
      HDDsize=`sysctl -a | grep "${SearchString}" | cut -d' ' -f 5`
   fi

###   echo ${SingleHDD}" is size "${HDDsize}

   ### the following is  4Tb ... 4000000000000
   ### the following is 25Gb ...   25000000000

   if [ $HDDsize -gt               25000000000 ] ; then
      drives=${drives}" "${SingleHDD}
   fi
done

echo $drives


This code gives me PossibleHDDs of "da0 da1 ada0 ada1 ada2 ada3 ada4" and drives of "ada0 ada1 ada2 ada3 ada4".
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
Last edited:

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
I asked a question about motherboard temps and was provided with a hint to search in the output from 'sysctl -a'.
This brings back memories for certain. Years ago I was trying to get MB temps for my system and I eventually did but over time it was not worth keeping up with it because I had to load a module that wasn't normally loaded in the FreeNAS distribution and there were a lot of frequent updates and those changes were not persistent. Also all the temps were fine. Some components are very hot on a MB and that is the design. I think keeping track of the HD temps is enough but that is already built into FreeNAS these days for a maximum threshold. The CPU temps would be worth monitoring for a new build but once that is done, there is no need to monitor it further unless you need to know if the CPU fan has failed. That would be a nice feature to add into FreeNAS, a CPU temp threshold, not a fan failure alarm because that would be too difficult based on the way FreeNAS is built. Linux is much easier with this but we are not using Linux.

This is not a very easy problem to solve as one answer will not fit everyone and it requires a bit of work so I'll drop a bread crumb for you. Depending on your motherboard you will likely have to load software to monitor your sensors on your motherboard like ipmitool, coretemp, bsdhwmon, lmmon, mbmon, acpi_ibm, etc... Once you have it loaded and then with some luck you should be able to use systctl to view the values. I would do a Google search for something like "motherboard temperature freebsd" and add in your motherboard manufacturer or model into the search. It may help you discover the correct module to load and save you a bunch of testing time.
 

Ruff.Hi

Patron
Joined
Apr 21, 2015
Messages
271
I found a solution that seems to report the MB temp - a thread here earlier this year suggested it. At least the temp agrees with what my ipmi is reporting.
Code:
### MB Temperature
MBTemp=`ipmitool sensor list all | grep "MB Temperature" | cut -d' ' -f 6`
echo "MB temperature "$MBTemp" C" >> ${logfile}


I've included this snippet into my CPU / HDD script that then turns around and emails the logfile to my google account.

BTW - coretemp is loaded in FreeNAS ... it is reported in sysctl.
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
I found a solution that seems to report the MB temp. At least the temp agrees with what my ipmi is reporting.
Code:
### MB Temperature
MBTemp=`ipmitool sensor list all | grep "MB Temperature" | cut -d' ' -f 6`
echo "MB temperature "$MBTemp" C" >> ${logfile}


I've included this snippet into my CPU / HDD script that then turns around and emails the logfile to my google account.
Could you state the MB this works with?
 

Ruff.Hi

Patron
Joined
Apr 21, 2015
Messages
271

Bi1a1Y

Cadet
Joined
Dec 11, 2014
Messages
9
ok im a jackass.. i wasn't running the script as root. disregard the rest of this post

Hi,

so i'm tyring to implement your smart script. i ssh'd in to the nas using my login (not root) i created a directory in my home folder called scripts and then placed your code in a file smart.sh. i edited the file adding my email and tried da1 da2... etc i also tried ada1 ada2...etc (since when i got to storage>view disks in the gui the drives are named ada1 ada2.. etc.

i gave the file executable permisions as you suggested and even tried changing the owner to root. i receive the email report however i get the following (shortened )..


Code:
########## SMART status report summary for all drives ##########

+------+---------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+
|Device|Serial         |Temp|Power|Start|Spin |ReAlloc|Current|Offline |Seek  |Total     |High  |Command|
|      |               |    |On   |Stop |Retry|Sectors|Pending|Uncorrec|Errors|Seeks     |Fly   |Timeout|
|      |               |    |Hours|Count|Count|       |Sectors|Sectors |      |          |Writes|Count  |
+------+---------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+
|da1   |               |  |     |     |     |       |       |        |   N/A|       N/A|   N/A|    N/A|
|da2   |               |  |     |     |     |       |       |        |   N/A|       N/A|   N/A|    N/A|
|da3   |               |  |     |     |     |       |       |        |   N/A|       N/A|   N/A|    N/A|
|da4   |               |  |     |     |     |       |       |        |   N/A|       N/A|   N/A|    N/A|
+------+---------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+



########## SMART status report for da1 drive (: ) ##########

/dev/xpt0 control device couldn't opened: Permission denied
Unable to get CAM device list
/dev/da1: Unable to detect device type
Please specify device type with the -d option.

Use smartctl -h to get a usage summary


i'm sure the solution is super simple especially since everyone in the thread has got it working with few problems if any..

thanks for any help..
PS i'm super new at this stuff.
 
Last edited:

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
Can you please post the output of camcontrol devlist ?
 

Bi1a1Y

Cadet
Joined
Dec 11, 2014
Messages
9
Can you please post the output of camcontrol devlist ?

when i'm ssh'd as root it runs correctly.

for camcontrol devlist i get

Code:
[root@freenas] ~# camcontrol devlist
<KINGSTON SV300S37A120G 603ABBF0>  at scbus1 target 0 lun 0 (pass0,ada0)
<WDC WD60EFRX-68MYMN1 82.00A82>    at scbus2 target 0 lun 0 (pass1,ada1)
<WDC WD60EFRX-68MYMN1 82.00A82>    at scbus3 target 0 lun 0 (pass2,ada2)
<WDC WD60EFRX-68MYMN1 82.00A82>    at scbus4 target 0 lun 0 (pass3,ada3)
<WDC WD60EFRX-68MYMN1 82.00A82>    at scbus5 target 0 lun 0 (pass4,ada4)
<SanDisk Cruzer Blade 1.27>        at scbus8 target 0 lun 0 (pass5,da0)

i presume this is all correct.

i'm gonna try your other scripts too and then attempt setting up cron. (sorry i didn't know how to delete my previous post)
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
Ok, so just to be sure, you need to put ada0 to ada4 in the drives list. Now, as far as I can understand your problem was just that you didn't execute it as root, so now it's fixed, right?
 

Bi1a1Y

Cadet
Joined
Dec 11, 2014
Messages
9
Ok, so just to be sure, you need to put ada0 to ada4 in the drives list. Now, as far as I can understand your problem was just that you didn't execute it as root, so now it's fixed, right?

yep all working its absolutely amazing your a genius.. thanks a lot.
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
Ok, perfect :)

No problem, and thanks for the compliment ;)
 

Ruff.Hi

Patron
Joined
Apr 21, 2015
Messages
271
ohh another way to see disks. What other magic, secret commands to you know? I realized today that the code I use to get the mobo temp, can also give me the fan speeds. If I have the fan speeds, I can create a script that tells me if a fan fails (ie zero RPMs).
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
All the commands I use are in the "Useful Commands" link in my signature ;)

In theory if a fan fails the MB (if capable and correctly configured) should shutdown the server but, yeah, I don't trust too much this kind of fail-safe. Do your own, it's always better :)
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
I've finally added the SAS version of the SMART script \0/ :D

@depasseg will be happy :)
 

depasseg

FreeNAS Replicant
Joined
Sep 16, 2014
Messages
2,874
What! A separate script? Boy oh boy, it's hard to find good, free help. j/k Thank you for your efforts!! :smile:
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
While I was at it I modified the self-adaptive method for the drives to avoid USB drives (that "small" thing has just ate 2 hours of my time (one line scripts are the hell)...) as there was a high demand for it.

I also modified the summary of the SATA version of the SMART script (replaced the total seeks that was useless by the UDMA CRC errors and added the age (in days) of the last SMART test) ;)
 

Ruff.Hi

Patron
Joined
Apr 21, 2015
Messages
271
My UPS doesn't have output.voltage. This is what it does have ...
battery.charge: 100
battery.charge.low: 10
battery.charge.warning: 50
battery.date: not set
battery.mfr.date: 2015/03/27
battery.runtime: 2108
battery.runtime.low: 120
battery.type: PbAc
battery.voltage: 13.6
battery.voltage.nominal: 12.0
device.mfr: APC
device.model: Back-UPS ES 650G1
device.serial: 4B1513P37600
device.type: ups
driver.name: usbhid-ups
driver.parameter.pollfreq: 30
driver.parameter.pollinterval: 2
driver.parameter.port: /dev/ugen0.7
driver.version: 2.7.2
driver.version.data: APC HID 0.95
driver.version.internal: 0.38
input.sensitivity: high
input.transfer.high: 139
input.transfer.low: 92
input.transfer.reason: input voltage out of range
input.voltage: 114.0
input.voltage.nominal: 120
ups.beeper.status: enabled
ups.delay.shutdown: 20
ups.firmware: 906.W1 .D
ups.firmware.aux: W1
ups.load: 20
ups.mfr: APC
ups.mfr.date: 2015/03/27
ups.model: Back-UPS ES 650G1
ups.productid: 0002
ups.serial: 4B1513P37600
ups.status: OL
ups.timer.reboot: 0
ups.timer.shutdown: -1
ups.vendorid: 051d

I am assuming I should report on input.voltage.nominal? Any other suggestions?
 
Top