Skip to content

ESXi-Arm on Raspberry Pi - Send CPU Temperature to Graphite

With the recently released ESXi-Arm-based driver for the Raspberry Pi's GPIO interface, it is possible to poll the Pies CPU temperature. With the provided module, I've created a quick script that you can run on your Raspi to send the CPU temperature to a Graphite host.

I've created 2 scripts that are available on Github (github.com/fgrehl/esxi-raspi). I've also modified the pimon library to automatically use the correct vmgfx device so that you no longer have to fix the pimonLib/__init__.py file.

pimon_temp.py (github.com/fgrehl/esxi-raspi/blob/main/pyUtil/pimon_temp.py)
The pimon_temp.pty script prints the current temperature on a given interval. If you run the script without arguments, it will print the temperature every 10 seconds:

# python pimon_temp.py
Polling CPU temperature every 10 seconds...
CPU Temperature: 48.0 C

If you want faster or slower output, just add the interval in seconds as the first argument:

python pimon_temp.py 2
Polling CPU temperature every 2 seconds...
CPU Temperature: 47.0 C
CPU Temperature: 48.0 C

pimon_tempgraphite.py (github.com/fgrehl/esxi-raspi/blob/main/pyUtil/pimon_tempGraphite.py)
The pimon_tempgraphite.py script sends data to a Graphite host. The Carbon Server has to be configured in the script itself:

Port 2003 outgoing is blocked by default in the firewall, so the shell is going to stuck when you run the script. As this is a non-production system, I just disabled the firewall:

# esxcli network firewall set --enabled false

You can then start the script.

# python pimon_tempGraphite.py
servers.esx9-virten-lab.cputemp 48.0 1604949554
servers.esx9-virten-lab.cputemp 49.0 1604949564
servers.esx9-virten-lab.cputemp 47.0 1604949574

 

Run the script automatically on ESXi Startup
If you want to run the script automatically on startup, you can add it to the /etc/rc.local.d/local.sh file. Make sure to add the command before the "exit 0" command.

Add the following line (Replace with your datastore name or ID):

/bin/python /vmfs/volumes/[Datastore]/pyUtil/pimon_tempGraphite.py >/dev/null &

Make sure to run it asynchronously (& at the end ) and pipe the output to /dev/null. The file should look like this:

The following graph has been created with Grafana, an open-source visualization frontend for Graphite:

Troubleshooting
If you get the following error message:

sock.connect((CARBONSERVER, CARBONPORT))
TimeoutError: [Errno 110] Connection timed out

Switch of the ESXi Firewall

# esxcli network firewall set --enabled false

---

In 1 out of 1000 polls, the script can't read temperature data and sends a 0 to graphite.

servers.esx8-virten-lab.cputemp 40.0 1605030894
[Errno 110] Connection timed out
servers.esx8-virten-lab.cputemp 0 1605030904
servers.esx8-virten-lab.cputemp 40.0 1605030914

As a workaround, I updated the script to only send data when the temperature is not "0". Don't apply this lazy workaround when your Raspi runs with a liquid nitrogen cooler.
github.com/fgrehl/esxi-raspi/commit/8f425853d68335bd7776746414c655efba72292c

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *