大家好,我是小斐呀。
很久没有更新网络设备采集配置了,今天这篇文章带来了关于中兴交换机的指标采集和可视化。
采集器使用 SNMP Exporter 通过开启中兴交换机的 SNMP 实现指标暴露,通过 VictoriaMetrics 体系下的 vmagent 组件去作为抓取器,主动去 pull 采集器暴露的指标数据,最后通过 VWR(VictoriaMetrics remote_write) 协议实现把抓取到的数据持久化到 VictoriaMetrics 时序库中,最终通过 Grafana 对指标数据实现监控可视化的目标,并且可以为后面的指标告警做准备,具体的架构如下所示:
中兴交换机完美适配支持 SNMP 协议采集,在实际场景中可能用的设备型号都挺高的,如果有更多对指标高精度(毫秒或秒级)需求可使用 Telemetry 技术,据我了解中兴交换机稍微高一点的版本都适配支持 Telemetry 遥测,如果在接口流量微突发有需求,可以研究一下 Telemetry 遥测技术栈。
采集配置
现在需要利用 SNMP Exporter 采集中兴交换机,首先说明一点官方下载的 SNMP Exporter 二进制包是有问题的, Web UI 还没有彻底修复,都已经 0.29.0 版本了,我也是真的服了,上游依赖的 exporter-toolkit 源代码其实已经修复了,只不过没有发新版本,这就导致下游的 SNMP Exporter 一直有问题,如果需要修复,可以基于源码重新构建,我对上游依赖的 exporter-toolkit 重新打包发了新版本。
利用配置文件生成器生成中兴交换机的最终采集配置文件,下面是主要的几个模块说明:
上面的采集模块是通过下面的配置文件生成的,最终使用的采集配置是生成后的配置文件,可以通过修改该配置文件自定义你需要的指标模块,或者在我的配置文件上做增删改查动作即可:
auths:
zte_auth:
version: 2
community: public
modules:
zte_system:
walk:
- 1.3.6.1.2.1.1.5
- 1.3.6.1.2.1.1.3
- 1.3.6.1.4.1.3902.3.600.3.2
- 1.3.6.1.4.1.3902.3.600.3.7
- 1.3.6.1.4.1.3902.3.600.2.1.1.3.0.0.1.0
- 1.3.6.1.4.1.3902.3.600.2.1.1.4.0.0.1.0
- 1.3.6.1.4.1.3902.3.600.2.1.1.5.0.0.1.0
- 1.3.6.1.4.1.3902.3.600.2.1.1.6.0.0.1.0
- 1.3.6.1.4.1.3902.3.600.2.1.1.7.0.0.1.0
- 1.3.6.1.4.1.3902.3.600.2.2.1.2
- 1.3.6.1.4.1.3902.3.600.2.2.1.9
- 1.3.6.1.4.1.3902.3.600.2.3.1.2
- 1.3.6.1.4.1.3902.3.600.2.3.1.4
- 1.3.6.1.4.1.3902.3.600.2.3.1.6
- 1.3.6.1.4.1.3902.3.600.2.4.1.3
- 1.3.6.1.4.1.3902.3.600.2.4.1.5
- 1.3.6.1.4.1.3902.3.600.2.4.1.7
max_repetitions: 25
retries: 3
timeout: 5s
allow_nonincreasing_oids: false
use_unconnected_udp_socket: false
lookups:
overrides:
zxr10SystemVersion:
ignore: false
type: DisplayString
sysUpTime:
type: counter
ignore: false
scale: 0.01
zxr10SystemStartupTime:
type: counter
ignore: false
scale: 0.01
filters:
zte_interface:
walk:
- 1.3.6.1.2.1.31.1.1.1.1
- 1.3.6.1.2.1.2.2.1.7
- 1.3.6.1.2.1.2.2.1.8
- 1.3.6.1.2.1.31.1.1.1.15
- 1.3.6.1.2.1.2.2.1.4
- 1.3.6.1.2.1.2.2.1.2
- 1.3.6.1.2.1.2.2.1.6
- 1.3.6.1.2.1.31.1.1.1.6
- 1.3.6.1.2.1.31.1.1.1.10
- 1.3.6.1.2.1.2.2.1.13
- 1.3.6.1.2.1.2.2.1.19
- 1.3.6.1.2.1.2.2.1.14
- 1.3.6.1.2.1.2.2.1.20
- 1.3.6.1.2.1.31.1.1.1.7
- 1.3.6.1.2.1.31.1.1.1.8
- 1.3.6.1.2.1.31.1.1.1.9
- 1.3.6.1.2.1.31.1.1.1.11
- 1.3.6.1.2.1.31.1.1.1.12
- 1.3.6.1.2.1.31.1.1.1.13
max_repetitions: 25
retries: 3
timeout: 5s
allow_nonincreasing_oids: false
use_unconnected_udp_socket: false
lookups:
- source_indexes: [ifIndex]
lookup: ifName
# drop_source_indexes: false
overrides:
ifDescr:
ignore: false
type: DisplayString
ifName:
ignore: true
type: DisplayString
ifPhysAddress:
ignore: false
type: PhysAddress48
filters:
dynamic:
- oid: 1.3.6.1.2.1.2.2.1.7
targets:
- "1.3.6.1.2.1.2.2.1.8"
- "1.3.6.1.2.1.31.1.1.1.15"
- "1.3.6.1.2.1.2.2.1.4"
- "1.3.6.1.2.1.2.2.1.2"
- "1.3.6.1.2.1.31.1.1.1.6"
- "1.3.6.1.2.1.31.1.1.1.10"
- "1.3.6.1.2.1.2.2.1.13"
- "1.3.6.1.2.1.2.2.1.19"
- "1.3.6.1.2.1.2.2.1.14"
- "1.3.6.1.2.1.2.2.1.20"
- "1.3.6.1.2.1.31.1.1.1.7"
- "1.3.6.1.2.1.31.1.1.1.8"
- "1.3.6.1.2.1.31.1.1.1.9"
- "1.3.6.1.2.1.31.1.1.1.11"
- "1.3.6.1.2.1.31.1.1.1.12"
- "1.3.6.1.2.1.31.1.1.1.13"
- "1.3.6.1.2.1.2.2.1.6"
values: ["1"]
zte_optical:
walk:
- 1.3.6.1.4.1.3902.3.103.11.1.1.2
- 1.3.6.1.4.1.3902.3.103.11.1.1.3
- 1.3.6.1.4.1.3902.3.103.11.1.1.4
- 1.3.6.1.4.1.3902.3.103.11.1.1.16
- 1.3.6.1.4.1.3902.3.103.11.1.1.18
- 1.3.6.1.4.1.3902.3.103.11.1.1.20
- 1.3.6.1.4.1.3902.3.103.11.1.1.24
max_repetitions: 25
retries: 3
timeout: 5s
allow_nonincreasing_oids: false
use_unconnected_udp_socket: false
lookups:
- source_indexes: [zxr10OpticalIfIndex]
lookup: zxr10OpticalIfName
# drop_source_indexes: true
overrides:
zxr10OpticalIfName:
ignore: true
type: DisplayString
zxr10OpticalFpType:
ignore: false
type: DisplayString
zxr10OpticalSWaveLenth:
ignore: false
type: DisplayString
zxr10OpticalSRxPower:
ignore: false
type: DisplayString
regex_extracts:
'':
- regex: '(.*)'
value: '$1'
zxr10OpticalSTxPower:
ignore: false
type: DisplayString
regex_extracts:
'':
- regex: '(.*)'
value: '$1'
zxr10OpticalSTemperature:
ignore: false
type: DisplayString
regex_extracts:
'':
- regex: '(.*)'
value: '$1'
filters:
dynamic:
- oid: 1.3.6.1.4.1.3902.3.103.11.1.1.3
targets:
- "1.3.6.1.4.1.3902.3.103.11.1.1.4"
- "1.3.6.1.4.1.3902.3.103.11.1.1.16"
- "1.3.6.1.4.1.3902.3.103.11.1.1.18"
- "1.3.6.1.4.1.3902.3.103.11.1.1.20"
- "1.3.6.1.4.1.3902.3.103.11.1.1.24"
values: ["1"]
上面配置文件星球里面也有说明视频,解释如何自定义自己的采集模块需求,可以更好的帮助你基于内部的实际设备做定制化。
如何使用
把 SNMP Exporter 下的 generator 生成器构建生成的采集配置文件放入配置文件中加载即可,生成器生成采集配置文件如下步骤所示:
把中兴交换机 mib文件放入指定目录中;使用 SNMP Exporter源码构建生成器二进制文件;编写构建自定义 生成器配置文件,也就是我上面的提供的类似 yml 结构文件;使用生成器二进制文件以及对应的参数去生成最终的采集配置文件。
如下所示,把中兴交换机对应版本的私有 mib 文件放入对应的目录 /opt/snmp_exporter/generator/mibs/zte 下(需要把公有 MIB 也放入该目录下以解决私有 MIB 依赖的问题),然后执行相关命令对 mib 文件做语法和依赖错误检查:
/opt/snmp_exporter/generator/generator --fail-on-parse-errors parse_errors -m /opt/snmp_exporter/generator/mibs/zte
把 generator_zte_sw.yml 放入 /opt/snmp_exporter/conf/zte 目录下,执行如下命令生成即可:
/opt/snmp_exporter/generator/generator --no-fail-on-parse-errors generate -m /opt/snmp_exporter/generator/mibs/zte -g /opt/snmp_exporter/conf/zte/generator_zte_sw.yml -o /opt/snmp_exporter/conf/zte/snmp_zte.yml
如果执行上面的命令后,输出的以下信息没有任何报错,就代表配置文件语法没有任何问题, 并且 oid 都能正常读取以及 mib 节点依赖都是正常:
最终得到可以直接放在 SNMP Exporter 下加载运行的 snmp_zte.yml 文件,这个文件也就是中兴交换机的最终采集配置文件(如果直接拿这个文件做采集使用,注意对认证模块的信息修改后在使用)。
运行采集
把生成好的配置文件 snmp_zte.yml 放入加载配置文件的文件夹中,如下所示:
将 snmp_exporter 的作为服务运行,新建服务启动文件 /etc/systemd/system/snmp_exporter.service
[Unit]
Description=snmp_exporter
After=network.target
[Service]
ExecStart=/opt/snmp_exporter/snmp_exporter --config.file=/opt/snmp_exporter/conf/snmp_*.yml --snmp.module-concurrency=3
Restart=on-failure
[Install]
WantedBy=multi-user.target
把 snmp_zte.yml 放入 /opt/snmp_exporter/conf/ 目录下,启动并运行测试如下:
加载最终的采集配置文件后,还是需要打开 SNMP Exporter 的 WEB UI 单独测试指标采集是否成功:
Target填写需要采集对象的IP比如这里我填写中兴交换机的管理地址Auth填写采集配置文件中定义的认证模块名称,如zte_authModule填写采集配置文件中定义的指标模块名称,如zte_system,zte_interface,zte_optical
抓取配置
当通过 SNMP Exporter 的 web ui 页面测试通过后,就可以开始配置服务发现和抓取配置。
由于 SNMP Exporter 是基于 pull 模式,需要配置 job_name 以定时抓取指标数据存入时序库中,实现数据的持久化,方便后续的可视化和告警查询。
如果使用 Prometheus 时序库,我们可以直接编辑 prometheus.yml 文件,在 prometheus.yml 文件下直接配置对应的抓取任务:
scrape_configs:
# 抓取中兴交换机指标数据
-job_name:"ZTE_Switch"
scrape_interval:30s
scrape_timeout:25s
file_sd_configs:
-files:
-/opt/prometheus/targets/zte_sw.yml
refresh_interval:2m
metrics_path:/snmp
relabel_configs:
-source_labels:["__address__"]
target_label:__param_target
-source_labels:["__param_target"]
target_label:instance
-target_label:__address__
replacement:172.16.10.10:9116
-source_labels:["module"]
target_label:__param_module
-source_labels:["auth"]
target_label:__param_auth
如果使用 VictoriaMetrics 时序库,我习惯在在前面使用 vmagent 去做抓取组件,然后在 vmagent 中配置对应的抓取任务:
scrape_configs:
# 抓取中兴交换机指标数据
-job_name:"ZTE_Switch"
scrape_interval:30s
scrape_timeout:25s
file_sd_configs:
-files:
-/etc/victoriametrics/vmagent/zte_sw.yml
metrics_path:/snmp
relabel_configs:
-source_labels:["__address__"]
target_label:__param_target
-source_labels:["__param_target"]
target_label:instance
-target_label:__address__
replacement:172.16.10.10:9116
-source_labels:["module"]
target_label:__param_module
-source_labels:["auth"]
target_label:__param_auth
在批量抓取交换机的场景下,我这里使用了文件服务发现,我们需要在对应目录下添加中兴交换机的管理信息, zte_sw.yml 文件模版内容如下:
-labels:
module:zte_system,zte_interface,zte_optical
auth:zte_auth
brand:ZTE
role:switch
region:guangzhou
targets:
-172.16.10.111
-172.16.10.100
-172.16.10.120
务必注意配置文件的格式,很多小伙伴,容易犯文本格式错误,然后抓瞎。
可视面板
通过数据持久化后,我可以更好的基于 Grafana 来实现监控仪表板,如下就是中兴交换机的简单仪表板展示,如果不满意还可以更好的自定义需求:
end
如果你对这块的有需求或者想沟通交流,可以加入之前建立的群,到群里咨询或交流即可,加群可公众号后台私信加我,我拉你进群。
推荐站内搜索:最好用的开发软件、免费开源系统、渗透测试工具云盘下载、最新渗透测试资料、最新黑客工具下载……




还没有评论,来说两句吧...