FreeNAS Stat Monitor

Possibly… Probably… I was unaware of SNMP when I went down this rabbit hole. It wasn’t until
this post that I realized that I could have gone that route.

Have you successfully set up SNMP sensors from FreeNAS? Is it pretty simple? Do you get access to the same information, warning messages etc?

To be fair, ive got no idea, it really depends how much data FreeNAS publishes through SNMP and how usable that data is. I havent played with FreeNAS and SNMP yet, but im using SNMP to monitor different servers and devices (like PDUs) and the results are mixed depending on how much information particular system or device exposes

FreeNAS exposes basic info over SNMP (such as 1/5/15 load - at OIDs from 1.3.6.1.4.1.2021.10.1.3.1 to _3).

However, it can be further extended by including “pass .1.3.6.1.2.1.25.1.8 /bin/sh /mnt/name_of_script.sh” in the SNMP service configuration.

I’ve only added temperature sensor (see below), however result of pretty much any command can be passed to SNMP and monitored over by HA.

#!/bin/sh
echo .1.3.6.1.2.1.25.1.8 # increment for additional sensors
echo gauge
sysctl -a | egrep -E "cpu\.0+\.temp" | awk '{print $2}'
exit 0

OK! Now I am intrigued! I assumed what SNMP gave you is what you got. But if you can pass anything, that would be awesome. Not only for notification, but I like having all my stat collection in one place and tracked in HA. Could probably accomplish the same thing or better in a FN jail with some type of logging server… Been thinking about looking into that to track network traffic from my pfSense router and such. Prioritizing time for these nice to haves is always the thing.

I originally thought it would be cool to have API integration because I could auto unlock my FreeNAS encrypted drives from HA and get stat data. I wasn’t able to get the unlock to work on my first crack and then found other things to do that were higher priority and never got back to it.

Can include result of custom scripts over SNMP on pfsense too.

As default SNMP daemon is limited, I installed net-snmp package, changed port from default 161, then in the advanced configuration added the location of the scripts:

extend .1.3.6.1.2.1.25.1.8 proctemp /bin/sh /home/user/custom/proctemp.sh

and the actual script for monitoring temperature on core 0:

#! /bin/bash 

sysctl -n dev.cpu.0.temperature |tr -d C

I installed a crazy custom API package to get stats from pfSense (link). SNMP may have been better?

My box is a fanless J1900 with pfblockerng, snort, ClamAV (comes with Squid) and net-snmp packages (I only added a few custom sensors over SNMP, was mostly looking to get processor temperature into HA).

Usually stays at 0.4-0.5 on 15 min load, sometimes going up to 0.7-0.8 (processor is quad core so this is quite low) and 70-72 degrees C.

1 Like

Got it all setup. Just a small glitch of missing the Alert level and message sensors

image

Also what other Stats can we get from the FreeNAS? I was hoping to read the status of my ups that is linked to my FreeNAS.

@Dayve67

I seem to remember that you’ll get an “Unknown” if there is no message or alert level. Maybe you can set a condition that if the others were able to pull data and Alert message is null, then make it “Ok.” or something.

In order to get your UPS status, you’ll probably have to go the SNMP sensor route and create a custom SNMP sensor. I would also like to set this up for the same reason. I just haven’t gotten around to playing with SNMP yet. With the API you can access your UPS settings, but it doesn’t look like you can get the current status: http://api.freenas.org/resources/services.html#ups

I got it to work. I was missing “object” in the value_template. But in the process I forced an alert by setting the disk temp low. I have the alert showing now but it will not clear even when I reset my disk temp alert and clear it from the Freenas UI. Restarted HA and it still holds.

value_template: '{{ value_json.objects[0].message }}'

image

It could either be your scan_interval or FreeNAS could still be reporting it in the API. Try getting the message from your browser and see what FreeNAS is reporting. http://hostipaddress/api/v1.0/system/alert/?format=json

@gremblin

Well it looks to be a FreeNAS issue by this old Bug report. At least with 11.3 it looks like the feature will be there. https://redmine.ixsystems.com/issues/11117

On another note did you get the stats from pfSense working?

I installed a crazy custom API package to get stats from pfSense ([link ](https://community.home-assistant.io/t/pfsense-stat-monitor/61070)). SNMP may have been better?

pfSense is working fine for me using the ‘crazy api’ addon, I haven’t tried using SNMP.

con you share your config here?

Her you go. Its pretty easy. Just copy and paste the sensors below and paste them in your sensor.yaml file.
Replace the IP of mine that is 192.168.1.9 with the IP of your Freenas. Also put in your user name and password on each sensor.

  - platform: rest
    name: FN_disk1_report
    json_attributes:
      - name
      - status
      - used_pct
      - is_decrypted
    resource: http://192.168.1.9/api/v1.0/storage/volume/Disk1/?format=json
    value_template: '{{ value_json.status }}'
    username: your_user
    password: your_password
    authentication: basic
    headers:
      Content-Type: application/json

  - platform: template
    sensors:
      fn_disk1_pct_used:
        value_template: '{{ states.sensor.fn_disk1_report.attributes["used_pct"].title() }}'
        entity_id: sensor.fn_disk1_report
      
  - platform: rest
    name: FN_alert_level
    resource: http://192.168.1.9/api/v1.0/system/alert/?format=json
    value_template: '{{ value_json.objects[0].level }}'
    username: your_user
    password: your_password
    authentication: basic
    headers:
      Content-Type: application/json
  
  - platform: rest
    name: FN_alert_message
    resource: http://192.168.1.9/api/v1.0/system/alert/?format=json
    value_template: '{{ value_json.objects[0].message }}'
    username: your_user
    password: your_password
    authentication: basic
    headers:
      Content-Type: application/json
  
  - platform: rest
    name: FN_version
    json_attributes:
      - fullversion
      - name
      - version
    resource: http://192.168.1.9/api/v1.0/system/version/?format=json
    value_template: '{{ value_json.fullversion }}'
    username: your_user
    password: your_password
    authentication: basic
    headers:
      Content-Type: application/json

  - platform: rest
    name: FN_disk2_report
    json_attributes:
      - name
      - status
      - used_pct
      - is_decrypted
    resource: http://192.168.1.9/api/v1.0/storage/volume/Disk2/?format=json
    value_template: '{{ value_json.status }}'
    username: your_user
    password: your_password
    authentication: basic
    headers:
      Content-Type: application/json

  - platform: template
    sensors:
      fn_disk2_pct_used:
        value_template: '{{ states.sensor.fn_disk2_report.attributes["used_pct"].title() }}'
        entity_id: sensor.fn_disk2_report

Then if your using Lovelace just make a card with all the sensor entities.

Just for fun If you would like to see the API of the FreeNAS you can enter some thing like this: ```
http://192.168.1.9/api/v1.0/storage/volume/Disk1/?format=json

in your browser, It will ask for your user and password. Dont forget to change the IP to yours.

Thanks :+1:

For those who may be interested, this is my current Lovelace View for FN related data:

3 Likes

That’s awesome! Thanks for sharing! :slight_smile:

Very nice. Mine was basic compared to yours. Can you share yours with me now?

Hello Dayve67.

Please see: Home Assistant and FreeNAS.

My configuration and Lovelace view have grown since the above, but it’ll get you started. When you need more, let me know.

1 Like