FreeNAS Stat Monitor

and does anyone know how to get the memory in use, i looked at the api docs and could not find it.

thanks!

While you might be concerned in monitoring memory usage for FN/TN, this is also completely irrelevant due to the followings:

  • there are multiple components of the memory in use - see below printscreen of top (similar to processor usage, in regard of which 1,5,15m loads are more relevant indicators); stricto senso, you could compute memory in use as total installed memory less free memory (which gets us to the second point that is actually the most important);

image

  • the OS uses, by design, almost the entire physical memory (actually large free memory values would be an inefficiency indicator). As such, except for some very obscure cases, largest performance increase would be obtained by installing as much RAM as the system supports (preferably ECC, but the majority of FN/TN systems in the wild do real good without it).

I guess that you could, instead, monitor the free memory case it goes higher than a certain threshold but it is unlikely that the system would leave large RAM values unused.

and how do i get that to a sensor?? :smiley:

Haven’t looked in detail at the API v2 but I think that it is possible to get virtually any value from FN/TN with command line and custom SNMP OIDs sensors.

it is not in the api , i have cheked, and no idea how to create an oid sensor. have any example?

Check my topic posted here Advanced SNMP monitoring, part two: FreeNAS

1 Like

Hi!

My CPU temp suddenly stopped working. i cant figure out why. any ideas?

Now it only reports unknown.

- platform: rest
  name: TrueNAS_local_backup_cpu_temp
  resource: http://XXX.XXX.X.XX/api/v2.0/reporting/get_data
  headers:
    Authorization: !secret tn2_bearer_token
    Content-Type: application/json
    User-Agent: Home Assistant
  device_class: temperature
  unit_of_measurement: '°C'
  scan_interval: 60
  method: POST
  payload: >-
    {
        "graphs":[{"name":"cpu"},{"name":"cputemp"}],
        "reporting_query":{"unit":"HOUR","page":0,"aggregate":true}
    }
  json_attributes_path: "$.[0]"
  json_attributes:
    - aggregations
  value_template: >-
    {% set tn = namespace(temp=0, cores=4) %}
    {% for core in range(0, tn.cores) %}
    {% set tn.temp = tn.temp + value_json[1].data[358][core] %}
    {% endfor %}
    {{ "%.1f"% (tn.temp / tn.cores) }}

Is there someone that have this currently working?

i also get this in the logs

2021-11-03 20:39:04 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: dict object has no element 1 when rendering '{% set tn = namespace(temp=0, cores=4) %} {% for core in range(0, tn.cores) %} {% set tn.temp = tn.temp + value_json[1].data[358][core] %} {% endfor %} {{ "%.1f"% (tn.temp / tn.cores) }}'

and my version of Truenas is: Version: “TrueNAS-12.0-U6”

This works well in U5; my config is exactly the same as yours. In the change logs for U6 there seem to have been some changes to the graphs for temperature. My guess is that the rest format has changed. Try looking at the return of the REST call on a browser. The template might have to be modified.

EDIT: I just tested the update to U6 and reporting seems broken on my system. There are no CPU temperature graphs on the TrueNAS UI and trying the REST calls yields errors. I guess it’s a TrueNAS bug, unless the calls have changed, but then they would’ve updated the UI as well I guess.

Ok, then we know why. I have tried to search for any related changes and i cant find any. Maybe it gets fixed in the next release. Or maybe raise a issue ticket to Truenas

It was reported a little while ago: https://jira.ixsystems.com/browse/NAS-112690. There is a possible fix in the bug report if you feel adventurous. Or you can revert to U5 for the time being unless U6 brings a feature or bugfix that you were waiting for. Just go to System > Boot and make the U5.1 boot environment the default one. Disclaimer: I’ve done this and it works fine, but do at your own risk.

1 Like

Thank you!

I tried to tinker with the template. But i cant get it to work. Any one knows how to fix this? :slight_smile:

It would definitely help to know what you’ve changed or what you’re trying to do. :smile:

haha, sorry.

I tried to mess with the code i posted eralier to the “fix” they posted in the jira ticket. i changed 0 to 1 on different areas but no change. but this can also be my lack of understanding code.

BR

Looks like this should be fixed in the latest TrueNAS update

TrueNAS CORE 12.0-U6.1 has been released! This is a hotpatch release that includes Samba security releases, a fix for CPU temperature reporting, an adjustment for the default dataset checksum, and a small fix for the Dashboard.

Hi!

I can confirm that it works with the latest TN release

1 Like

Hi! Can somebody help me get the Free Memory from the API? I am trying to get the information based on reporting.get_data, just as with the CPU temp, but I cannot get my head around the JSON part of it.

I guess I should extract the “memory” graph which returns

  • memory-wired_value
  • memory-inactive_value
  • memory-laundry_value
  • memory-active_value
  • memory-free_value

But I am not able to get the values (or the aggregations) into the sensor.

Thanks!

With TrueNAS, a free memory report is pointless. The software is designed to use almost all of the installed memory.

1 Like

Hi there,

I have been following along with posts in this thread and I have found my self stuck on monitoring pool status. What I currently have is below. I am also quite confused on what /id/0 means I can’t seam to find out how to know what id I need. I have tried 0,1,2. I only have one volume currently on my nas.
When I add to the dashboard I get sensor.nas_pool_pct_used unavailable. If I use the entity sensor.nas_pool I get a 0

#Storage percentage
  - platform: rest
    name:  nas_pool
    resource: http://host/api/v2.0/pool/id/0
    username: XXXX
    password: XXXX
    headers:
      Content-Type: application/json
      User-Agent: Home Assistant
    value_template: '{{ value_json["status"] }}'
    json_attributes_path: '$.topology.data[0].stats'
    json_attributes:
      - allocated
      - size
    scan_interval: 1800
  - platform: template
    sensors:
      nas_pool_pct_used:
        friendly_name: "% Used"
        value_template: ' {{ (state_attr("sensor.nas_pool", "allocated") / state_attr("sensor.nas_pool", "size") * 100) | round(1) }} '
        unit_of_measurement: "%"

Hi @EthanDH ,

The /id/0 part depends on the TrueNAS api. There’s no easy way to figure out what id your pool has or where you have to pull the values that you want from. The best way is to explore the api with the command line (a few posts up the thread there is some info on that).

That said, the value takes a bit to populate, up to 30min, so not seeing it right away doesn’t necessarily mean it’s not working.