Glances Integration: How to access Network bandwidth and GPU info?

Hi @matteoconti92, all you have to do is remove the other elements that you don’t need from the original code I posted. If you have 2 disks, your configuration.yaml would need the below code.

Before you do this, you need to make sure you’re using the correct API endpoint. For me, glances api endpoint is accessible here: http://192.168.1.2:61208/api/3/all. You need to replace it with where your glances is running in the code below. Everything else should be the same.

rest:
  - resource: http://192.168.1.2:61208/api/3/all
    sensor:"
      - name: diskio_0
        value_template: '{{ value_json[0] | default }}'
        json_attributes_path: "$.diskio.0"
        json_attributes:
          - time_since_update
          - disk_name
          - read_bytes
          - write_bytes
      - name: diskio_1
        value_template: '{{ value_json[1] | default }}'
        json_attributes_path: "$.diskio.1"
        json_attributes:
          - time_since_update
          - disk_name
          - read_bytes
          - write_bytes
    verify_ssl: false
    timeout: 30
    scan_interval: 3

sensor:
  - platform: template
    sensors:
      horizon_c_drive_read_bytes:
        value_template: >-
                {% set read_byte = state_attr('sensor.diskio_0', 'read_bytes') %}
                {% set time_since = state_attr('sensor.diskio_0', 'time_since_update') %}
                {% if (read_byte != None ) and (time_since != None ) %}
                  {{ ((read_byte | int) / (time_since | int) / 1000000) | round (2) }}
                {% endif %}
        availability_template: >-
                {{ states("sensor.diskio_0") not in ["unknown", "unavailable", "none"] }}
        unit_of_measurement: 'MB/s'
  - platform: template
    sensors:
      horizon_c_drive_write_bytes:
        value_template: >-
                {% set write_byte = state_attr('sensor.diskio_0', 'write_bytes') %}
                {% set time_since = state_attr('sensor.diskio_0', 'time_since_update') %}
                {% if (write_byte != None ) and (time_since != None ) %}
                  {{ ((write_byte | int) / (time_since | int) / 1000000) | round (2) }}
                {% endif %}
        availability_template: >-
                {{ states("sensor.diskio_0") not in ["unknown", "unavailable", "none"] }}
        unit_of_measurement: 'MB/s'

it’s what I’ve tried but show me the stats for disk “zram0”…I’ve a SSD thought USB named in Glances “sda”…how can I have the stats for that disk I/O?!
really thanks

I’m not a glances expert…but, if you upload the full output of your api end-point (I.E., http://192.168.1.2:61208/api/3/all) to pastebin.com for me to look at, I can try to see what elements are available on your Glances instance. Please make sure you copy/paste the full output (without changing anything) to pastebin.com.

Looks like this feature will be added in the hopefully not so distant future: Network information missing in glances · Issue #93381 · home-assistant/core (github.com)

That reminds me, I recently added a Top 5 Processes Task Manager in addition to Network, Disk, and other useful info via configuration.yaml and RESTful integration. It works great and very low on the resources… updating every 6 seconds. I’ll post the code for this soon:

Code below, it’s all there under a single rest: integration; respective templates, etc all builtin.

Home Assistant Glances RESTful code - Pastebin.com

PS: One very useful tip (if using the code above), Use a command-line similar to below for your glances instance to reduce resource consumption significantly. It disables all addons… then, only loads the ones that are actually needed by the RESTful code above.

Glances.exe -w -q -0 --disable-autodiscover --disable-history --disable-plugin all --enable-plugin connections,cpu,diskio,fs,mem,memswap,network,processcount,processlist,uptime
2 Likes

I just came across this and I love this! Thanks for posting your config!

Can I ask how you added the Top 5 processes? Is it in the code under PROCESS 0 EXE?

I’m looking to do that for my linux servers but I feel like the command might be way different.

Thanks!

Hi @snipes040 I’m not certain how much different Glances is on Windows verses Linux. I’m guessing not much difference. Can you post the API JSON response you get from your Glances webserver in a text file and share it over here?

Please use the command-line parameters I provided to startup Glances webserver with API. On Linux it shouldn’t be too much different. Make sure you install all the Glances plugins mentioned in the command-line before starting Glances.

Then, paste your Glances URL in your web browser’s address bar. For example, the URL I use is: http://192.168.1.2:61208/api/3/all

Once you share the text file with the full API response, I’ll know if what we need to change in the code (hopefully not much).

To answer your question about the Top 5 processes… everything in the code I posted that mentions processlist will create all the sensors needed for the Top 5 processes. The top 5 processes card you see in the screenshot is actually a Home Assistant Markdown card with the respective code:

type: markdown
content: |-
  <div class="tg-wrap">
  <table width=100%>
  <thead>
    <tr>
      <td><b>CPU</b></td>
      <td><b>Process</b></td>
      <td><b>MEM (P)</b></td>
      <td><b>MEM (V)</b></td>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>{{ states('sensor.process_0_cpu_percent') }}%</td>
      <td>{{ states('sensor.process_0_exe') }}</td>
      <td>{{ states('sensor.process_0_res') }}M</td>
      <td>{{ states('sensor.process_0_virt') }}M</td>
    </tr>
    <tr>
      <td>{{ states('sensor.process_1_cpu_percent') }}%</td>
      <td>{{ states('sensor.process_1_exe') }}</td>
      <td>{{ states('sensor.process_1_res') }}M</td>
      <td>{{ states('sensor.process_1_virt') }}M</td>
    </tr>
    <tr>
      <td>{{ states('sensor.process_2_cpu_percent') }}%</td>
      <td>{{ states('sensor.process_2_exe') }}</td>
      <td>{{ states('sensor.process_2_res') }}M</td>
      <td>{{ states('sensor.process_2_virt') }}M</td>
    </tr>
    <tr>
      <td>{{ states('sensor.process_3_cpu_percent') }}%</td>
      <td>{{ states('sensor.process_3_exe') }}</td>
      <td>{{ states('sensor.process_3_res') }}M</td>
      <td>{{ states('sensor.process_3_virt') }}M</td>
    </tr>
    <tr>
      <td>{{ states('sensor.process_4_cpu_percent') }}%</td>
      <td>{{ states('sensor.process_4_exe') }}</td>
      <td>{{ states('sensor.process_4_res') }}M</td>
      <td>{{ states('sensor.process_4_virt') }}M</td>
    </tr>
  </tbody>
  </table>
  </div>
title: Top 5 Processes

Is there a need to submit and enhancement request to enable the updated glances api network stats to appear in the glances integration?

I saw the request to have this added which was merged in May 2023, but the Glances integration still doesn’t produce the new data and there doesn’t appear to be a request anywhere to have it added.

I don’t understand the relationship between the merged request and the glances integration, but it’s clear the the current version of the glances integration doesn’t produce network entities and I don’t see anywhere where it’s an outstanding ER or pending change.

1 Like

Added in HA 2024.5:
network traffic
disk I/O
GPU
uptime

Have fun!

1 Like