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

I just installed the Glances integration to be able to monitor a remote PC’s resources (Ethernet Rx/s, Tx/s, GPU utilization, CPU, disk, etc). …the same information I would see when opening up Glances locally (see screenshot below).

To my surprise, only very basic Glances entities were added to Home Assistant (CPU, disk, and RAM utilization).

What do I need to do to be able to access the information circled in RED below as entities? Hopefully, I don’t have manually create REST-based sensors for all the missing entities. Or even worse, not being able to access this information at all.

Thanks so much in advance for your assistance.

1 Like

You would have to open a feature request as these are the only currently supported sensors: https://www.home-assistant.io/integrations/glances/#integration-entities

1 Like

That is what you will have to do.

When I wrote the glances integration and the underlaying Python module glances_api I was limited to what my own hardware provided.

We could always extent the glances sensor.

3 Likes

Where can I create FR for GPU sensors?

Hi, is there any plans to extend the glances integration with sensors such as eth0 bandwidth, GPU usage, amount of vm’s running etc.

You guys might be disappointed if you’re waiting for any further support for the existing Glances integration.

I decided to create my own RESTful sensors for Glances CPU, Disk size, Disk utilization, GPU, and Network information, please find the below fully working example configuration with a single REST call every x seconds with respective templates for calculations.

Below, is my own personal configuration.yaml (unchanged). It took me literally months to create/refine this configuration since there wasn’t any documentation or examples floating around anywhere that I could find. You may need to tweak the disk config, since I only needed to monitor logical drive C: and E:

Good luck!

rest:
  - resource: http://192.168.1.2:61208/api/3/all
    sensor:
      - name: Horizon C Drive Used
        value_template: '{{ value_json.fs.0.percent }}'
        unit_of_measurement: "%"
      - name: Horizon E Drive Used
        value_template: '{{ value_json.fs.1.percent }}'
        unit_of_measurement: "%"
      - 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
      - name: Horizon Uptime
        value_template: '{{ value_json.uptime | regex_replace(find="[\"]", replace="") | regex_replace(find="(?<=( (\d{1})|(\d{2})):\d{2}):\d{2}", replace=" hours") }}'
      - name: Horizon CPU
        value_template: '{{ value_json.cpu.total | round }}'
        unit_of_measurement: "%"
      - name: Horizon RAM
        value_template: '{{ value_json.mem.percent | round }}'
        unit_of_measurement: "%"
      - name: Horizon Pagefile
        value_template: '{{ value_json.memswap.percent | round }}'
        unit_of_measurement: "%"
      - name: gpu
        value_template: '{{ value_json[0] | default }}'
        json_attributes_path: "$.gpu.0"
        json_attributes:
          - name
          - mem
          - proc
          - temperature
      - name: network
        value_template: '{{ value_json[0] | default }}'
        json_attributes_path: "$.network.0"
        json_attributes:
          - interface_name
          - time_since_update
          - rx
          - tx
          - cx
    verify_ssl: false
    timeout: 30
    scan_interval: 3

sensor:
  - platform: systemmonitor
    resources:
      - type: disk_use_percent
        arg: /home
      - type: memory_use
      - type: memory_use_percent
      - type: processor_use
  - 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'
  - platform: template
    sensors:
      horizon_e_drive_read_bytes:
        value_template: >-
                {% set read_byte = state_attr('sensor.diskio_1', 'read_bytes') %}
                {% set time_since = state_attr('sensor.diskio_1', '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_1") not in ["unknown", "unavailable", "none"] }}
        unit_of_measurement: 'MB/s'
  - platform: template
    sensors:
      horizon_e_drive_write_bytes:
        value_template: >-
                {% set write_byte = state_attr('sensor.diskio_1', 'write_bytes') %}
                {% set time_since = state_attr('sensor.diskio_1', '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_1") not in ["unknown", "unavailable", "none"] }}
        unit_of_measurement: 'MB/s'
  - platform: template
    sensors:
      horizon_gpu_name:
        value_template: '{{ state_attr("sensor.gpu", "name") }}'
  - platform: template
    sensors:
      horizon_gpu_memory:
        value_template: '{{ state_attr("sensor.gpu", "mem") | round }}'
        unit_of_measurement: "%"
  - platform: template
    sensors:
      horizon_gpu_processor:
        value_template: '{{ state_attr("sensor.gpu", "proc") }}'
        unit_of_measurement: "%"
  - platform: template
    sensors:
      horizon_gpu_temperature:
        value_template: '{{ state_attr("sensor.gpu", "temperature") }}'
        unit_of_measurement: "°C"
  - platform: template
    sensors:
      horizon_download_speed:
        value_template: >-
                {% set receive = state_attr('sensor.network', 'rx') %}
                {% set time_since = state_attr('sensor.network', 'time_since_update') %}
                {% if (receive != None ) and (time_since != None ) %}
                  {{ ((receive | int) / (time_since | int) * 8 / 1000000) | round (2) }}
                {% endif %}
        availability_template: >-
                {{ states("sensor.network") not in ["unknown", "unavailable", "none"] }}
        unit_of_measurement: 'MB/s'
  - platform: template
    sensors:
      horizon_upload_speed:
        value_template: >-
                {% set transmit = state_attr('sensor.network', 'tx') %}
                {% set time_since = state_attr('sensor.network', 'time_since_update') %}
                {% if (transmit != None ) and (time_since != None ) %}
                  {{ ((transmit | int) / (time_since | int) * 8 / 1000000) | round (2) }}
                {% endif %}
        availability_template: >-
                {{ states("sensor.network") not in ["unknown", "unavailable", "none"] }}
        unit_of_measurement: 'MB/s'
  - platform: template
    sensors:
      horizon_total_speed:
        value_template: >-
                {% set total = state_attr('sensor.network', 'cx') %}
                {% set time_since = state_attr('sensor.network', 'time_since_update') %}
                {% if (total != None ) and (time_since != None ) %}
                  {{ ((total | int) / (time_since | int) * 8 / 1000000) | round (2) }}
                {% endif %}
        availability_template: >-
                {{ states("sensor.network") not in ["unknown", "unavailable", "none"] }}
        unit_of_measurement: 'MB/s'

5 Likes

Ahh brilliant, with a few tweaks, I was able to use this.
Newbie question, I run my HA from a vm in Unraid.
My goal is to get bandwidth usage of my 2 NICs, at the moment it seems your code only gives me the bandwidth of my HA instance.

Any ideas?

I’m glad you could use it. I didn’t install the Home Assistant Glances Addon. I only have experience with Glances installed and running on the host OS itself. In my case, I installed Glances on my Windows 10 PC (Python module) …and, access it via REST calls from my Home Assistant VM. My VM also happens to be running on the same Windows 10 host.

Are your two NICs on your Unraid box? Presuming you’ve installed the HA Glances Addon, you’ll have to uninstall it. Then, install Glances on your Unraid OS itself (outside your VM), if possible …in order for Glances to see your NICs.

No Glances is not installed in HA, I have glances installed in Unraid itself which is the underlying OS and using the glances add-on (not integration option) to pull some of the sensors into Home Assistant.
If you see the attached screenshot, you’ll see the sensor for the ethernet adapter, however when using the add-on,there’s no sensor for the ethernet adapter.
Another thing I noticed is that there’s no VM instance shown in Glances but there is for Docker.
I’m not too concerned about that though, I’m more concerned about a sensor for the ethernet adapter.

You’ll only be able to use whatever is provided by the Glances API:

http://192.168.1.2:61208/api/3/all

To see if that data is available to you, you can open that link in your web browser (whatever your IP: port is for glances), save the text to a text file, then open the file in a code editor like Microsoft Code to format the code as JSON (so it looks similar to mine below). In my case, I only have one network card:

  "network": [
    {
      "interface_name": "Local Area Connection",
      "time_since_update": 30.490334033966064,
      "cumulative_rx": 104223283040,
      "rx": 1269746,
      "cumulative_tx": 65485863122,
      "tx": 1212118,
      "cumulative_cx": 169709146162,
      "cx": 2481864,
      "is_up": true,
      "speed": 1048576000,
      "key": "interface_name"
    },

If you see your network cards in the response under “network”, you will be able to use that data to make them into sensors. You’ll have to look at my code as a reference to figure out the appropriate respective REST calls.

1 Like

OK I have that, another novice question, how do I now incorporate that in my config.yaml file?
As I’m getting an error once I paste the code.

What error? Can you post the error(s)? I tend to struggle with debugging issues on HA as well, but I’ll try to help.

This is basically what I have so far:

rest:

  • resource: http://192.168.1.4:61208/api/3/all
    sensor:
    • name: network
      value_template: ‘{{ value_json[0] | default }}’
      json_attributes_path: “$.network.0”
      json_attributes:
      • interface_name: eth0,
      • time_since_update: 3.998791456222534,
      • rx: 13360,
      • tx: 56112,
      • cx: 69472,
        verify_ssl: false
        timeout: 30
        scan_interval: 3

sensor:

  • platform: template
    sensors:
    horizon_download_speed:
    value_template: >-
    {% set receive = state_attr(‘sensor.network’, ‘rx’) %}
    {% set time_since = state_attr(‘sensor.network’, ‘time_since_update’) %}
    {% if (receive != None ) and (time_since != None ) %}
    {{ ((receive | int) / (time_since | int) * 8 / 1000000) | round (2) }}
    {% endif %}
    availability_template: >-
    {{ states(“sensor.network”) not in [“unknown”, “unavailable”, “none”] }}
    unit_of_measurement: ‘MB/s’
  • platform: template
    sensors:
    horizon_upload_speed:
    value_template: >-
    {% set transmit = state_attr(‘sensor.network’, ‘tx’) %}
    {% set time_since = state_attr(‘sensor.network’, ‘time_since_update’) %}
    {% if (transmit != None ) and (time_since != None ) %}
    {{ ((transmit | int) / (time_since | int) * 8 / 1000000) | round (2) }}
    {% endif %}
    availability_template: >-
    {{ states(“sensor.network”) not in [“unknown”, “unavailable”, “none”] }}
    unit_of_measurement: ‘MB/s’
  • platform: template
    sensors:
    horizon_total_speed:
    value_template: >-
    {% set total = state_attr(‘sensor.network’, ‘cx’) %}
    {% set time_since = state_attr(‘sensor.network’, ‘time_since_update’) %}
    {% if (total != None ) and (time_since != None ) %}
    {{ ((total | int) / (time_since | int) * 8 / 1000000) | round (2) }}
    {% endif %}
    availability_template: >-
    {{ states(“sensor.network”) not in [“unknown”, “unavailable”, “none”] }}
    unit_of_measurement: ‘MB/s’

Not too sure where I may be going wrong or right as I have no experience dealing with rest or JSON codes.
This is what I was able to glean from http://192.168.1.4:61208/api/3/all:

“network”: [
{
“interface_name”: “eth0”,
“time_since_update”: 3.998791456222534,
“cumulative_rx”: 5209358935,
“rx”: 13360,
“cumulative_tx”: 1190125340,
“tx”: 56112,
“cumulative_cx”: 6399484275,
“cx”: 69472,
“is_up”: true,
“speed”: 104857600,
“key”: “interface_name”
},

But unsure of how to make it work. sorry for the novice questions.

Sorry for the late response. It looks like all your formatting was lost when you pasted the code. Indentation makes a difference in yaml code such as configuration.yaml. You’ll have to paste the code with the formatting intact like mine. The spacing/indentation should match the rest of your configuration.yaml.

Most importantly, even if your code is correct with the right formatting… your JSON response shows only one network adapter… HA instance - Eth0. You need to get your network adapters to be included in the JSON API response. I’m no expert in Glances… but, you can ask some experts on resources like Glances mailgroup, Glances Github Issue, or Gitter Chat.

Hello! Great job, I have implemented some sensors that are very helpful!
I have removed from the api what would be the part of the Opetarito System and others but I don’t know how to transform it to sensors as you have done, could you guide me a little how to continue?

"system": [
  {
    "os_name": "Windows",
    "hostname": "DESKTOP-KR42JC2",
    "platform": "64bit",
    "os_version": "10 SP0",
    "hr_name": "Windows 10 SP0 64bit"
   }, 
Thanks a lot

Hello, thanks for this. I’m interested in applying this on my dashboard. I have little to zero experience in this field. If I understand correctly, I need to copy this on the configuration.yaml then how can I show it on my dashboard? Any sample code? Thank you.

Hi…everyone know how to create a sensor for the Disk I/O Activity?!
I tried but nothing :frowning:

What I’ve to do if I want to see JUST the Disk IO sensor?! I tried but I’m not able to extract from your config :frowning: