『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 5967|回复: 4

[基础教程] 用SNMP监控路由器、服务器等的流量

[复制链接]

3

主题

26

帖子

103

积分

论坛分享达人

积分
103
金钱
77
HASS币
0
发表于 2017-9-9 12:03:29 | 显示全部楼层 |阅读模式
效果图:

TIM图片20170909115656.png

搬运自https://community.home-assistant.io/t/snmp-bandwidth-monitor/7122

先在路由器中开启SNMP,我的路由器是UBNT ERX

TIM图片20170909114702.png

configuration.yaml中添加:

baseoid可能不同设备不一样,可以用snmpwalk软件确认,下载地址: https://support.solarwinds.com/S ... erformance_Monitor_(NPM)/SolarWinds_SNMP_Walk_A_new_tool_for_collecting_SNMP_MIB_walks

oid在线查询: http://oid-info.com


### EDGE ROUTER ###
  - platform: snmp
    name: snmp_wan_in
    host: 192.168.2.1
    baseoid: 1.3.6.1.2.1.2.2.1.16.2


  - platform: snmp
    name: snmp_wan_out
    host: 192.168.2.1
    baseoid: 1.3.6.1.2.1.2.2.1.10.2

    
  - platform: template
    sensors:
      internet_speed_in:
        friendly_name: 'Internet Speed In'
        value_template: '{{ ((states.input_slider.internet_traffic_delta_in.state | float ) / 1000000 ) | round(2) }}'
        unit_of_measurement: 'Mbps'

  - platform: template
    sensors:
      internet_speed_out:
        friendly_name: 'Internet Speed Out'
        value_template: '{{ ((states.input_slider.internet_traffic_delta_out.state | float ) / 1000000 ) | round(2) }}'
        unit_of_measurement: 'Mbps'

  - platform: statistics
    name: 'WAN Traffic IN'
    entity_id: sensor.internet_speed_in

  - platform: statistics
    name: 'WAN Traffic OUT'
    entity_id: sensor.internet_speed_out
## Custom Input Sliders ##
input_slider:
  internet_traffic_delta_in:
   name: "Traffic IN Delta"
   initial: 0
   min: 0
   max: 1000000000000

  internet_traffic_delta_out:
   name: "Traffic OUT Delta"
   initial: 0
   min: 0
   max: 1000000000000


automations中添加:
- alias: Monitor Traffic In
  trigger:
    platform: state
    entity_id: sensor.snmp_wan_in
  action:
    - service: input_slider.select_value
      data_template:
        entity_id: input_slider.internet_traffic_delta_in
        value: '{{ ((trigger.to_state.state | int - trigger.from_state.state | int) * 8 ) / ( as_timestamp(trigger.to_state.last_updated) - as_timestamp(trigger.from_state.last_updated) ) }}'

- alias: Monitor Traffic Out
  trigger:
    platform: state
    entity_id: sensor.snmp_wan_out
  action:
  - service: input_slider.select_value
    data_template:
      entity_id: input_slider.internet_traffic_delta_out
      value: '{{ ((trigger.to_state.state | int - trigger.from_state.state | int) * 8 ) / ( as_timestamp(trigger.to_state.last_updated) - as_timestamp(trigger.from_state.last_updated) ) }}'


customs中添加:

sensor.internet_speed_in:
  friendly_name: '下载速度'
  icon: mdi:speedometer
sensor.internet_speed_out:
  friendly_name: '上传速度'
  icon: mdi:speedometer
sensor.wan_traffic_in_mean:
  friendly_name: '下载平均速度'
  icon: mdi:download
sensor.wan_traffic_out_mean:
  friendly_name: '上传平均速度'
  icon: mdi:upload



好了 搞定!

回复

使用道具 举报

123

主题

4626

帖子

1万

积分

管理员

囧死

Rank: 9Rank: 9Rank: 9

积分
16013
金钱
11302
HASS币
45
发表于 2017-9-9 12:11:22 | 显示全部楼层
感谢分享,权限奉上。

另外,这个snmp不是所有路由都支持吧?
回复

使用道具 举报

3

主题

26

帖子

103

积分

论坛分享达人

积分
103
金钱
77
HASS币
0
 楼主| 发表于 2017-9-9 13:41:49 | 显示全部楼层
Jones 发表于 2017-9-9 12:11
感谢分享,权限奉上。

另外,这个snmp不是所有路由都支持吧?

大部分都支持。。。 只要能刷机的路由器。。。
回复

使用道具 举报

1

主题

255

帖子

599

积分

高级会员

Rank: 4

积分
599
金钱
344
HASS币
0
发表于 2019-6-16 10:38:33 来自手机 | 显示全部楼层
谢谢分享!
回复

使用道具 举报

0

主题

6

帖子

44

积分

新手上路

Rank: 1

积分
44
金钱
38
HASS币
0
发表于 2023-2-17 21:38:41 | 显示全部楼层
提供一下OID供参考
Brand        Device/Firmware        OID
Aerohive        AP230        1.3.6.1.4.1.26928.1.1.1.2.1.2.1.1
Apple        Airport Express (2nd gen.) 7.6.9        1.3.6.1.2.1.3.1.1.2 or 1.3.6.1.2.1.4.22.1.2
Aruba        IAP325 on AOS 6.5.4.8        1.3.6.1.4.1.14823.2.3.3.1.2.4.1.1
BiPAC        7800DXL Firmware 2.32e        1.3.6.1.2.1.17.7.1.2.2.1.1
DD-WRT        unknown version/model        1.3.6.1.2.1.4.22.1.2
IPFire        2.25        1.3.6.1.2.1.4.22.1.2
MikroTik        unknown RouterOS version/model        1.3.6.1.4.1.14988.1.1.1.2.1.1
MikroTik        RouterOS 6.x on RB2011        1.3.6.1.2.1.4.22.1.2
OpenWrt        Chaos Calmer 15.05        1.3.6.1.2.1.4.22.1.2
OPNSense        19.1        1.3.6.1.2.1.4.22.1.2
pfSense        2.2.4        1.3.6.1.2.1.4.22.1.2
Ruckus        ZoneDirector 9.13.3        1.3.6.1.4.1.25053.1.2.2.1.1.3.1.1.1.6
TP-Link        Archer VR1600v        1.3.6.1.2.1.3.1.1.2.16.1
TP-Link        Archer VR2600v        1.3.6.1.2.1.3.1.1.2.19.1
TP-Link        Archer VR600        1.3.6.1.2.1.3.1.1.2
Ubiquiti        Edgerouter Lite v1.9.0        1.3.6.1.2.1.4.22.1.2
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-4-25 19:49 , Processed in 0.105893 second(s), 29 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表