HowTo: Monitoring FreeNAS CPU and DISK Temperature by SNMP

Status
Not open for further replies.

paddy01

Dabbler
Joined
Sep 18, 2013
Messages
19
Having been using FreeNAS for a while now I've learnt a hell of a lot from these forums, often what not to do so I thought I'd try and give something back!

I'm no expert and I certainly don't always follow the rules (no ECC Ram in my home server shhhhhh ;) ) but I hope this might be of help or interest to someone.


With FreeNAS 9.3 came the move to net-SNMP rather than bdsnmp and this means it's pretty trivial to enable monitoring of additional custom parameters via SNMP.

This tutorial looks at adding CPU and disk temperature monitoring.

Notes: My FreeNAS is an HP Microserver N54L with 5 x 3TB WD Red's in RaidZ2.
The script's here might need tweaking to match your hardware (number of CPU's etc).
The scripts are just quickly knocked up with no thought given to cleaning them up / combining them.
The custom OID's I've used were not in use on my FreeNAS install, you should check via snmpget to confirm they're also free on yours.
I won't cover how to add these extra parameters to your SNMP monitoring application. I use Cacti at home and Nagios at work, it's assumed if you want to do this you'll be familiar with those
and how to add new data sources to be monitored / graphed etc.


Step 1.
We need script to be called that will get the temperature's we want, I've used the below.

CPU0 - snmp-cpu-0-temp.sh

#!/bin/sh
if [ "$1" = "-g" ]
then
echo .1.3.6.1.2.1.25.1.8
echo gauge
sysctl -a | egrep -E "cpu\.0+\.temp" | awk '{print $2}' | cut -c 1,2,4
fi
exit 0

CPU1 - snmp-cpu-1-temp.sh

#!/bin/sh
if [ "$1" = "-g" ]
then
echo .1.3.6.1.2.1.25.1.9
echo gauge
sysctl -a | egrep -E "cpu\.1+\.temp" | awk '{print $2}' | cut -c 1,2,4
fi
exit 0


The above gives a result with 3 digits, avoiding the decimal place and removing the trailing "C". When you add this data to you will need a CDEF or similar to divide by 10 to counter this.

The -g option means echo the output to screen.


Step 2. Update SNMP config to include the new data.

In the FreeNAS gui, go to Services and the config for SNMP fill out the required fields and in Aux Parameters add the following:

pass .1.3.6.1.2.1.25.1.8 /bin/sh <path to script dir>/snmp-cpu-0-temp.sh
pass .1.3.6.1.2.1.25.1.9 /bin/sh <path to script dir>/snmp-cpu-1-temp.sh

Start the SNMP service.

SSH into your FreeNAS server and run:

snmpget -v2c -c public localhost .1.3.6.1.2.1.25.1.8
snmpget -v2c -c public localhost .1.3.6.1.2.1.25.1.9

All being well you'll see a 3 digit result (remember needs dividing by 10 for the actual result).

Pretty simple and of course easily extendible to add disk temperatures and pretty much anything else you can write a script for.

Cheers for reading,

Paddy

Credit : http://www.satsignal.eu/raspberry-pi/monitoring.html which gave me the base knowledge to expand SNMP monitoring with custom OID's etc.
 
Last edited:

ricardonadao

Cadet
Joined
Nov 10, 2015
Messages
8
Nice work Paddy.

I used a slightly different approach, but it is just the first version of it and there was no worry of "optimizing" or doing nice coding.

The main objective was to get something done as quick as possible that would show some graphs in cacti.

I used the "extend" option instead of the "pass" in the snmpd, which isn't the most clean option, but it does work when you want something quick and easy.
Still thinking if I will move to a "pass" instead of a "extend", since when you use the "pass" option the snmpd daemon will be "blocked" until it gets everything from the script, and "extend" doesn't block it... I could be wrong here, but it was my impression from what I read in the net-snmp documentation.
Also since I've used this approach in the past for some linux monitoring it was easier to select it.

However I think that the "next version" it will be more in the lines of using a proper indexed data_template and potentially a proper mib-extension.

But getting to the point.

Using some of the info from this forum that shows multiple ways of getting the CPU and HDD temperature of FreeBSD, I wrote a simple script that pulls the info and just list the values in separate lines:

show_cpu_temp () {

sysctl -a | egrep -E "cpu\.[0-9]\.temp" | cut -f2 -d" " | grep -o -E "([0-9]+\.[0-9])"
}

show_hdd_temp () {

for i in $(sysctl -n kern.disks | awk '{for (i=NF; i!=0 ; i--)
if(match($i, '/ada/')) print $i }' )
do
/usr/local/sbin/smartctl -a /dev/$i | grep "Temperature_Celsius" | awk '{print $10}'
done
}


Them created simple cacti templates to map the results to 2 graphs - 1 for CPU temp and 1 for HDD temp (HDD temp has only 4 drives since my installation have only 4 drives installed).

snmpd.conf addition:

extend cputemp "/usr/local/bin/freenas-snmp/freenas-info.sh cpu_temp"
extend hddtemp "/usr/local/bin/freenas-snmp/freenas-info.sh hdd_temp"


TODO:
- transform the data collection from cacti as something that is indexed, which takes the "lock down" of 4 CPUs and 4 HDDs from my script
- clean up some of the shellscript code, and potentially move to python or perl, to get it "cleaner"


Hope this gets some help.
 
Status
Not open for further replies.
Top