使用grafana+prometheus监控交换机
开启 SNMP 服务
snmp-agent
# 设置 SNMP v2c 只读团体名(例如 public)
snmp-agent community read public
# 设置 SNMP v2c 读写团体名(例如 private)
snmp-agent community write private
# 设置 SNMP 联系人和位置信息(可选)
snmp-agent sys-info contact admin@example.com
snmp-agent sys-info location Room-101
开启SNMPv2c,默认v3或者没开启
#查看开启了那些
[H3C]snmp-agent sys-info version v2c v3
[H3C]display snmp-agent sys-info version
# 或者 display snmp-agent sys-info
#开启
system-view
snmp-agent sys-info version v2c v3
save
测试 远程基本 SNMP 查询
yum install -y net-snmp-utils
snmpget -v2c -c public 172.10.10.252 1.3.6.1.2.1.1.1.0 -t 5
# 测试接口数量(如果交换机端口很多,会输出很多行)
time snmpwalk -v2c -c public 172.10.10.252 1.3.6.1.2.1.2.2.1.2 -t 10 | wc -l
export
wget https://github.com/prometheus/snmp_exporter/releases/download/v0.30.1/snmp_exporter-0.30.1.linux-amd64.tar.gz
./snmp_exporter --config.file=/root/snmp/snmp.yml
测试
curl "http://172.10.10.6:9116/snmp?target=172.10.10.252&module=system&auth=public_v2"
prometheus配置
- job_name: 'snmp-h3c-switch'
static_configs:- targets:
- '172.10.10.252' # 替换为实际IP
metrics_path: /snmp
params:
module: [if_mib] # 采集接口流量等标准指标
auth: [public_v2] # 使用 SNMP v2c,community 为 public
relabel_configs:
- '172.10.10.252' # 替换为实际IP
- source_labels: [address]
target_label: __param_target - source_labels: [__param_target]
target_label: instance - target_label: address
replacement: '172.10.10.6:9116' # 替换为 SNMP Exporter 地址
- targets:
面板 id
11169、20347