SNMP bandwidth monitor using statistics

What does this SnMP do?

https://community.ui.com/questions/SNMP-on-UDM-UDM-PRO/a2887f2a-c3dc-43ed-81a0-7fe0e63537ce#answer/1097781e-93ec-45c5-ae5f-b502389013fd

1 Like

What a disappointment!

I’m confused, is SNMP supported on the UDM Pro or not? There seems to be a setting for it, it doesn’t work?

Did you read the posts in the topic linked to?

that will provide snmp for any device the UDM/UDMP manages, such as access points and switches.

Apparently you can install SNMP now.

I think that is outdated as it seems Unifi has added SNMP to the Pro recently. Built in.

SNMP on UDM/UDM-PRO | Ubiquiti Community

And I have enabled it in my setting, but I still can’t connect. Maybe I have the wrong baseoid.

- platform: snmp
  name: "USG WAN in"
  host: 192.168.88.1
  baseoid: 1.3.6.1.2.1.31.1.1.1.6.2
  community: "public"
  version: "2c"
  scan_interval: 10

- platform: snmp
  name: "USG WAN out"
  host: 192.168.88.1
  baseoid: 1.3.6.1.2.1.31.1.1.1.10.2
  community: "public"
  version: "2c"
  scan_interval: 10

Nope. There is nothing in that topic that indicates SNMP is now shipped by default. The original poster made the same mistake as in my link. That setting is only for monitoring other devices connected to the UDM.

However as I said, you can add it now.

1 Like

I see, too bad Unifi does make that clear in their wording. We don’t all have the high level of expertise you have. I’m not sure I want to install third-party apps on my UDM, already unstable enough as it is.

This is only to enable snmp for connected unifi devices to the UDM, to run SNMP on the UDM itself you need to ssh into the udm and install it and run as service.

Here is a good tutorial for it:

2 Likes

I have SNMP running on my UDM Pro, but struggling to find the right OIDs to use for wan in/out

root@ubnt:/# snmpbulkwalk -v 2c -c home 192.168.0.1 1.3.6.1.2.1.31.1.1.1.1
iso.3.6.1.2.1.31.1.1.1.1.1 = STRING: "lo"
iso.3.6.1.2.1.31.1.1.1.1.2 = STRING: "dummy0"
iso.3.6.1.2.1.31.1.1.1.1.3 = STRING: "eth9"
iso.3.6.1.2.1.31.1.1.1.1.4 = STRING: "eth8"
iso.3.6.1.2.1.31.1.1.1.1.5 = STRING: "eth10"
iso.3.6.1.2.1.31.1.1.1.1.6 = STRING: "switch0"
iso.3.6.1.2.1.31.1.1.1.1.7 = STRING: "gre0"
iso.3.6.1.2.1.31.1.1.1.1.8 = STRING: "gretap0"
iso.3.6.1.2.1.31.1.1.1.1.9 = STRING: "erspan0"
iso.3.6.1.2.1.31.1.1.1.1.10 = STRING: "ip_vti0"
iso.3.6.1.2.1.31.1.1.1.1.11 = STRING: "sit0"
iso.3.6.1.2.1.31.1.1.1.1.12 = STRING: "br0"
iso.3.6.1.2.1.31.1.1.1.1.13 = STRING: "eth0"
iso.3.6.1.2.1.31.1.1.1.1.14 = STRING: "eth1"
iso.3.6.1.2.1.31.1.1.1.1.15 = STRING: "eth2"
iso.3.6.1.2.1.31.1.1.1.1.16 = STRING: "eth3"
iso.3.6.1.2.1.31.1.1.1.1.17 = STRING: "eth4"
iso.3.6.1.2.1.31.1.1.1.1.18 = STRING: "eth5"
iso.3.6.1.2.1.31.1.1.1.1.19 = STRING: "eth6"
iso.3.6.1.2.1.31.1.1.1.1.20 = STRING: "eth7"
iso.3.6.1.2.1.31.1.1.1.1.21 = STRING: "ifb0"
iso.3.6.1.2.1.31.1.1.1.1.22 = STRING: "ifb1"
iso.3.6.1.2.1.31.1.1.1.1.23 = STRING: "switch0.1"
iso.3.6.1.2.1.31.1.1.1.1.24 = STRING: "honeypot0"
iso.3.6.1.2.1.31.1.1.1.1.25 = STRING: "cni0"

eth 9 is my wan interface. any clues? :slight_smile:

So not this one?

That just gives me the total packets, not the utilisation

Ok, got it working after mashing some of these posts together:

sensor:
  - platform: snmp
    name: 'UDMP Up Time'
    host: 192.168.0.1
    baseoid: .1.3.6.1.2.1.25.1.1.0
    community: 'xxxx'
    version: '2c'
    scan_interval: 10
  - platform: snmp
    name: 'UDMP WAN in'
    host: 192.168.0.1
    baseoid: .1.3.6.1.2.1.2.2.1.10.4
    community: 'xxxx'
    version: '2c'
    scan_interval: 10
  - platform: snmp
    name: 'UDMP WAN out'
    host: 192.168.0.1
    baseoid: .1.3.6.1.2.1.2.2.1.16.4
    community: 'xxxx'
    version: '2c'
    scan_interval: 10
  - platform: derivative
    name: wan_in_der
    source: sensor.udmp_wan_in
    unit_time: s
    unit: B
  - platform: derivative
    name: wan_out_der
    source: sensor.udmp_wan_out
    unit_time: s
    unit: B    
  - platform: statistics
    name: 'UDMP WAN in Stats'                      
    entity_id: sensor.UDMP_wan_in                  
    sampling_size: 4                              
    max_age:                                      
     hours: 24                                   
  - platform: statistics                          
    name: 'UDMP WAN out Stats'                     
    entity_id: sensor.UDMP_wan_out
    sampling_size: 4
    max_age:
      hours: 24
  - platform: template
    sensors:
      internet_in_mbps:
        value_template: "{{ (state_attr('sensor.UDMP_wan_in_stats_mean','change_rate')|float*8*(state_attr('sensor.UDMP_wan_in_stats_mean', 'sampling_size')-1)/1000000)|round(2) }}"
        unit_of_measurement: 'MBps'
        entity_id: sensor.UDMP_wan_in_stats_mean
      internet_out_mbps:
        value_template: "{{ (state_attr('sensor.UDMP_wan_out_stats_mean','change_rate')|float*8*(state_attr('sensor.UDMP_wan_out_stats_mean', 'sampling_size')-1)/1000000)|round(2) }}"
        unit_of_measurement: 'MBps'
        entity_id: sensor.UDMP_wan_out_stats_mean
      wan_in_mbps:
            value_template:  "{{ [((states('sensor.wan_in_der')|float(none)*8)/1000000)|round(2, default=none),0]|max }}"
            unit_of_measurement: 'Mbps'
            friendly_name: "WAN In der UDMP"
      wan_out_mbps:
           value_template:  "{{ [((states('sensor.wan_out_der')|float(none)*8)/1000000)|round(2, default=none),0]|max }}"
           unit_of_measurement: 'Mbps'
           friendly_name: "WAN Out der UDMP"
1 Like

This is exactly what I’m looking for, so thank you for all the legwork (and @jimmyeao for the summarization).

One thing to add for anyone having SNMP problems with their UDM Pro – enabling it in the UI does NOT turn on SNMP for external access. That features enables it for SNMP management from the UDM Pro to the devices connected to it.

To properly enable SNMP on the UDM Pro, I used followed this guide: Enabling SNMP on Ubiquiti UDM Pro - Martin Rowan and, along with @jimmyeao 's snippet, worked perfectly.

1 Like

Hi there,

I’m thinking to give this a go, are the base oid’s always the same? I have a udm pro.

When I install SNMP as a Service, what happens when you restart the udm?

1 Like

do you got the latest config for your mini graph card as shown in this post?
still using the same configuration? statistics or derivative?

No, it depends on the vendor. You need to do an SNMP walk to identify your options.

1 Like

This was my solution using SNMPv3 to query a Cisco ISR router.

sensor:
  - platform: snmp
    name: "WAN Interface Down Octets"
    host: 192.168.150.1
    version: "3"
    username: !secret snmp_user
    auth_key: !secret snmp_auth_key
    auth_protocol: "hmac-sha"
    priv_key: !secret snmp_priv_key
    priv_protocol: "aes-cfb-128"
    # ifHCInOctets G0/0
    baseoid: 1.3.6.1.2.1.31.1.1.1.6.2
    state_class: total_increasing
    icon: mdi:cloud-download
    unit_of_measurement: "B"

  - platform: derivative
    # Calculate the throughput by sampling the SNMP sensor
    name: "WAN Down Throughput - Bps"
    source: sensor.wan_interface_down_octects
    unit_time: s
    round: 2

utility_meter:
  wan_down_usage_meter_bytes:
    unique_id: wan_down_data_usage_meter_bytes
    name: WAN Down Data Usage Meter - Bytes
    source: sensor.wan_interface_down_octets
    cycle: monthly

template:
  - sensor:   
    # Frontend sensors

    - name: "WAN Down Throughput - Mbps"
      unique_id: wan_down_throughput_mbps
      unit_of_measurement: Mbps
      # Convert derivative from Bps to Mbps
      state: "{{ ((states('sensor.wan_down_throughput_bps') | int) * 8 / 10**6) | round(1) }}"
      icon: mdi:cloud-download
      state_class: measurement

   - name: "WAN Down Usage - GiB"
      unique_id: wan_down_usage_gib
      unit_of_measurement: GiB
      # Convert SNMP sensor from B to GiB
      state: "{{ ((states('sensor.wan_interface_down_octects') | int) / 2**30) | round(2) }}"
      icon: mdi:cloud-download
      state_class: total_increasing
1 Like

I recently switch from using a USG to a UDM-Pro, so wanted to share the config for others…

sensor:
  - platform: snmp
    name: "UDM WAN in"
    host: 192.168.1.1
    baseoid: 1.3.6.1.2.1.2.2.1.10.4
    community: "public"
    version: "2c"
    scan_interval: 5

  - platform: snmp
    name: "UDM WAN out"
    host: 192.168.1.1
    baseoid: 1.3.6.1.2.1.2.2.1.16.4
    community: "public"
    version: "2c"
    scan_interval: 5

  - platform: statistics
    name: "UDM WAN in Stats"
    entity_id: sensor.udm_wan_in
    sampling_size: 4
    state_characteristic: change_second
    max_age:
      hours: 24

  - platform: statistics
    name: "UDM WAN out Stats"
    entity_id: sensor.udm_wan_out
    sampling_size: 4
    state_characteristic: change_second
    max_age:
      hours: 24


template:
  - sensor:
      - name: Downloads
        unique_id: 'sensor.udm_wan_in_mbps'
        icon: mdi:cloud-download
        state: "{{ states('sensor.udm_wan_in_stats')|float(0)*8/1024/1024|round(1) }}"
        unit_of_measurement: "MBps"

      - name: Uploads
        unique_id: 'sensor.udm_wan_out_mbps'
        icon: mdi:cloud-upload
        state: "{{ states('sensor.udm_wan_out_stats')|float(0)*8/1024/1024|round(1) }}"
        unit_of_measurement: "MBps"
3 Likes