InfluxDB Disk Temperature Logging by Serial Number (or chosen substitution)

InfluxDB Disk Temperature Logging by Serial Number (or chosen substitution) 1.0

It was brought to my attention that it may be useful for some of the forum members to log disk temperatures periodically to an influxDB (and then chart that with Grafana like the below example) to help with trends for individual disks or otherwise over time. (thanks for the ideas and help/testing from @NugentS https://www.truenas.com/community/t...toring-of-truenas-drives-in-particular.107406)

I already had that as part of my fan control script, but was able to "easily" grab that out and adapt it a bit to do just that part of the job.

Interesting things that it can do:
  • Log temperatures of disks by serial number
  • Substitute serial numbers for alternative text that helps to identify disks in a more human way... position, brand, slot, whatever is chosen
  • Log to either version 1 or version 2 (or later) of InfluxDB
  • Run on SCALE or CORE and produce the same outcomes
  • Filter to only log the disks that you want to log (explicit include with plain text or regex, including the possibility to filter out)
  • Log the temperature of your LSI HBA.
How to use it:

I'll assume you have an InfluxDB at this point already (setup hints below the picture if you need them).

Place a copy of the script file (from the download link in the top right of the resource) on your TrueNAS server (either in /root/ or in your pool (usually /mnt/tank/scripts or similar), then modify the top section according to the instructions in the file.

There should be no need to modify anything after line 83 (note that the top section may expand or even contract if you add or remove filters or substitutions, so line numbers may vary after that).

Mark the file as executable:
chmod +x /root/influxtemps.pl (modify path to suit what you did)

Run the script at least once (you might find it helpful to set $debug = 1 for the first run):
/root/influxtemps.pl

You will see a list of your disks (which follows the output of either sfdisk or camcontrol/nvmecontrol depending on the OS) and the output of smartctl -a for each disk, followed by a statement of the serial number and temperature for each.

Adjust your substitutions and disk/nvme filters as needed according to the instructions in the file.

If that works, you now just need to set a cron task to run that command /root/influxtemps.pl at your chosen frequency.

1689594413461.png



Setup for Influx:

For SCALE (this will mean you need to use version 2 of the influxdb commands) , using the InfluxDB app from TrueCharts (defaults or your own preferred settings for storage):

You'll need to do these things on your influx server's web console:

Create an admin user with a password (you won't see the console otherwise)

Select an org name (I called mine "home")

Create a bucket for use with TrueNAS (I called mine "freenas" due to legacy reasons)

Create an API token for the script to use (and make sure you capture it before dismissing the screen, as you can't see it again).

Those details then get edited into the script at the section at the beginning as explained there.



For CORE (this will mean you need to use version 1 of the influxdb commands), in a jail (or the plugin if you're super-lazy and don't mind some failures).

Create a jail.
Inside that jail:
pkg install influxdb curl libssh ca_root_nss

sysrc influxd_enable=YES

Restart the jail

create the db with: curl -XPOST 'http://influxdb.host:8086/query' --data-urlencode 'q=CREATE DATABASE "freenas"'

Details of the jail can then be added to the script.


For setting up in Grafana

Point your instance at the influxdb you're using above, then in a new dashboard panel, switch a query to raw view and set the query to something like this:

SELECT distinct("value") FROM "autogen"."DiskTemp" WHERE ("component"::tag =~ /.+/) AND $timeFilter GROUP BY time($__interval), component fill(null)

Then set the "Alias by" to $tag_component

You will then have all your temps charted on the same chart... you can use the filter section of the query WHERE ("component"::tag =~ /.+/) to get just one of your servers if you were using the $influxdb_hostname setting in the script (let's say for the example you had set it to "myhost_"), like this:
WHERE ("component"::tag =~ /myhost_.+/)
Author
sretalla
Downloads
236
Views
877
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from sretalla

Top