Monitoring the CPU temperature of your FreeBSD system in Zabbix

It is time again to add a few more metrics to be monitored on my
FreeBSD systems and I thought I’d add monitoring of the
CPU temperature this time.

In the past I had a system which was quite old and under a heavy load
it used to burn the CPU and then go down. Now I want to be sure that
this will never happen again and want to get some alerts whenever a
system reaches a critical point.

So, in this post I’m going to show you how to get your CPU’s
temperature monitored in Zabbix. The Operating System we use is
FreeBSD 9.0 running on a Intel i5 CPU.

Okay, the first thing we are going to do is to prepare our FreeBSD
system, so that we can gather some metrics from it, which we will
later add to Zabbix.

Let’s load the coretemp(4) module:

$ sudo kldload coretemp

In order to load the coretemp(4) module during boot-time, you should
add this line to your /boot/loader.conf file:

Once you’ve got your template and application it is time to create a
new UserParameter in Zabbix.

Create a new file under
/usr/local/etc/zabbix2/zabbix_agentd.conf.d/cpu_temp.conf (this
assumes that your zabbix_agentd.conf file includes the
/usr/local/etc/zabbix2/zabbix_agentd.conf.d/ directory). The
contents of the cpu_temp.conf file are shown below:

UserParameter=cpu.temp[*],/usr/local/bin/cpu_temp.sh $1

Below you can find a simple shell script that takes care of getting
the CPU temperature. The script will return the average CPU
temperature of all cores, or the temperature of the core you specify
it. So, now save this script in /usr/local/bin/cpu_temp.sh.

You can test that the script works by executing the script and passing
it an argument avg or the CPU core you want to get the temperature
of.

Now, it is time to add a few items in Zabbix. Navigate to the Items
tab of your template and create a new Zabbix item for getting the
average CPU temperature as shown on the screenshot below.

Lets create a graph of it as well, so navigate to the Graphs tab of
your template and create a new graph for your new item you’ve just
created. You could also create items for every core you have, that way
you can monitor the temperature of each core by creating an item with
a key like cpu.temp[0], which will give you the temperature of the
first core.

Once ready attach the template to your systems and start monitoring
your CPU’s temperature. Below you can find a few example screenshots
on one of my systems.

Here’s how graph of the average CPU temperature looks like:

And this is how the graph of the CPU temperature for all cores looks
like: