Systemmonitor

I have added a system health tab on my raspbian with the use of the systemmonitor all is working like a charm, I am finally getting the hang of yaml and all its pros and cons :smile: however, there is no information on the sysmonitor page that tells me how often these sensors are refreshing. So basically I look at values like the cpu load, but I have no idea how old it is. Is there any way I can manipulate how often they update?

    ### system monitor ###
  - platform: systemmonitor
    resources:
    - type: disk_use_percent
    - type: disk_free
    - type: memory_use_percent
    - type: network_in
      arg: eth0
    - type: network_out
      arg: eth0
    - type: ipv4_address
      arg: eth0
    - type: ipv4_address
      arg: wlan0
    - type: last_boot
    - type: processor_use

Will a simple scan interval like this work ?

     - platform: systemmonitor
       scan_interval: some value

Kind regards
DigiNorse

1 Like

scan_interval is not listed as a valid option in the documentation.

I looked through the source code and discovered it uses the psutil library.

However, I can’t find anything in the component’s code referring to polling so I don’t how it refreshes its data.

I also read how to use psutil to get cpu_percent. It says if you use interval=None it will report “system CPU times elapsed since last call or module import, returning immediately”. If you check the code, that’s precisely how the component gets cpu_percent.

The mystery to me is what constitutes the last call? The last time you looked at the value in the UI?? It remains unclear to me how often it performs ‘calls’ to update itself.

1 Like

I agree, I’m not fully sure how the insides of Home-Assistant work yet, but I don’t see anything in the component’s code that would update its data.

In that case, would it fall back to the default 30 second scan interval from homeassistant/components/sensor/__init__.py ?

That makes sense.

Only thing is my Python-fu isn’t strong enough to figure out what’s using SCAN_INTERVAL. There’s precious little code in sensor/__init__.py.

Yeah, it was a stab in the dark since I assume that there has to be some sort of default…

It is. All platforms which are polling can overwrite it. But you should know what you are doing.

The general issue is that we won’t want people to fine tune the polling interval on a large scale. This leads to performance issues on low-powered hardware, often just doesn’t make sense to get a measurement every second and is filling the database.

1 Like

Thanks! I didn’t realize there was a documentation base class that platform docs inherit from! :wink:

I’ve always considered the component/platform’s documentation as its master reference and didn’t know about that specific doc page which defines two, broadly applicable, options (entity_namespace and scan_interval).

I guess this solves the mystery of the systemmonitor’s default polling period (30 seconds).

BTW, the doc page you mentioned contains the following note:

These options are being phased out and are only available for single platform integrations.

Is that still true?

1 Like

I tried setting the scan_interval on the systemmonitor after trawling through code but it didn’t appear to have any effect :frowning:

According to my tests, the default scan_interval is 15 sec - at least for the processor_use sensor.
May be for other sensors the frequency is different.
Am I right?
What are values/value of frequency for sensors?

I don’t know; that post was made 3 years ago. If your results differ then those must be what it is today.

This is a card I used to estimate the scan_interval value:

type: vertical-stack
title: sysmon::scan_interval
cards:
  - type: entities
    entities:
      - entity: sensor.processor_use
        secondary_info: last-changed
  - type: history-graph
    hours_to_show: 1
    refresh_interval: 0
    entities:
      - entity: sensor.processor_use
  - type: custom:mini-graph-card
    <<: &ref_settings
      hours_to_show: 1
      update_interval: 0
      aggregate_func: last
      smoothing: false
      lower_bound: ~0
      line_width: 1
      entities:
        - entity: sensor.processor_use
    points_per_hour: 120
  - type: custom:mini-graph-card
    <<: *ref_settings
    points_per_hour: 240

The history-graph card shows data “as is” - every sensor’s update.
The mini-graph-card splits the whole time period (hours_to_show) to small intervals; number of intervals (points_per_hour) defines accuracy.

The 2nd mini-graph-card has a smaller points_per_hour value = 240 (freq 15 sec):

  • the graph has more curves;
  • the graph’s curves are NOT changing - just new curves are added.

The 1st mini-graph-card has a smaller points_per_hour value = 120 (freq 30 sec):

  • the graph has less curves;
  • the graph’s curves ARE changing - old curves are changing every 30 sec.

So I concluded that at least for the processor_use sensor the scan_interval = 15 sec.

Also I found that for network_in, network_out the scan_interval = 30 sec.
Surely I could make mistakes; that is why I need some confirmation…

1 Like

This line in systemmonitor’s code:

references this line:

Seems to be a default value for ALL integrations - unless it is not specified explicitly equal to some other value in some integration?