经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » 编程经验 » 查看文章
Prometheus监控之SNMP Exporter介绍和数据展现
来源:cnblogs  作者:十亩菠萝地  时间:2023/4/26 9:17:35  对本文有异议

由于技术能力有限,文章仅能进行简要分析和说明,如有不对的地方,请指正,谢谢??。

1 SNMP协议介绍

SNMP协议全称是:Simple Network Management Protocol,译为简单网络管理协议,是作为TCP/IP网络管理标准协议,为不同的设备提供统一接口,实现了网络设备之间的统一管理。

SNMP协议分为三个版本:

  1. SNMPv1是最初版本,基于团体名认证,安全性较差,返回报文的错误码较少。
  2. SNMPv2c也采用团体名认证,引入了GetBulk和Inform操作,支持更多的标准错误码信息和更多的数据类型。
  3. SNMPv3主要在安全性方面进行了增强,提供了基于USM(User Security Module)的认证加密和基于VACM(View-based Access Control Model)的访问控制。

不管哪个版本,SNMP协议由外部的网络管理系统NMS和运行在被管设备内部的SNMP Agent、被管对象和管理信息库MIB组成:

MIB数据库中的OID树状存储结构:树的节点表示被管理对象,它可以用从根开始的一条路径唯一地识别,这条路径就称为OID,如system的OID为1.3.6.1.2.1.1,interfaces的OID为1.3.6.1.2.1.2

可以从OID(如system的OID为1.3.6.1.2.1.1,interfaces的OID为1.3.6.1.2.1.2)中获取到被管理设备的当前运行状态。

2 SNMP Exporter介绍

SNMP Exporter是Prometheus的官方Exporter项目之一,可以容器运行或者二进制运行,项目地址:snmp_exporter。Exporter通过snmp.yml配置文件,将SNMP Agent的数据暴露在SNMP Exporter中,供Prometheus监控被管理设备的运行状态。

例如一个最简单的snmp.yml配置文件:

  1. Linux:
  2. version: 2
  3. auth:
  4. community: snmpexport
  5. walk:
  6. - 1.3.6.1.4.1.2021.11
  7. get:
  8. - 1.3.6.1.2.1.1.3
  9. metrics:
  10. - name: sysUpTime
  11. oid: 1.3.6.1.2.1.1.3
  12. type: gauge
  13. help: The time (in hundredths of a second) since the network management portion
  14. of the system was last re-initialized. - 1.3.6.1.2.1.1.3
  15. - name: ssCpuUser
  16. oid: 1.3.6.1.4.1.2021.11.9
  17. type: gauge
  18. help: The percentage of CPU time spent processing user-level code, calculated
  19. over the last minute - 1.3.6.1.4.1.2021.11.9
  20. - name: ssCpuSystem
  21. oid: 1.3.6.1.4.1.2021.11.10
  22. type: gauge
  23. help: The percentage of CPU time spent processing system-level code, calculated
  24. over the last minute - 1.3.6.1.4.1.2021.11.10
  25. - name: ssCpuIdle
  26. oid: 1.3.6.1.4.1.2021.11.11
  27. type: gauge
  28. help: The percentage of processor time spent idle, calculated over the last minute
  29. - 1.3.6.1.4.1.2021.11.11

这个配置文件中有一个模块为Linux,SNMP版本为v2c,团体名称为snmpexporter,监控的OID有:1.3.6.1.4.1.2021.11和1.3.6.1.2.1.1.3,根据OID所在的树状级别,采用不同方式的查询操作(walk或get),被监控的对象有sysUpTime、ssCpuUser、ssCpuSystem、ssCpuIdle

  • walk:实际上是SNMP GETNEXT,从SNMP Agent中获取一个或多个参数的下一个参数值。
  • get:从SNMP Agent中获取一个或多个参数值。

实际上还有GetBulk操作(SNMPv1不支持),基于GETNEXT实现,相当于执行多次GetNext,但是SNMP Exporter中不具备该查询操作。

3 使用SNMP Exporter监控Linux操作系统

被监控设备操作系统版本:Oracle Linux 7.9,SELinux状态:Permissive

3.1 监控设备安装和配置SNMP

  1. 安装net-snmp
    yum install -y net-snmp
  2. 配置SNMP团体名称
    echo 'rocommunity snmpexport 192.168.1.200'>/etc/snmp/snmpd.conf
  3. 重启snmpd服务
    systemctl restart snmpd
  4. 检查snmpd服务
    systemctl status snmpd|grep -E "Active"
    输出结果参考:
    Active: active (running) since Fri 2022-05-06 10:23:56 CST; 2min 4s ago
  5. 防火墙放通snmp服务
    firewall-cmd --permanent --add-service=snmp

    firewall-cmd --add-port=161/udp --permanent

3.2 docker部署SNMP Exporter

  1. docker中下载snmp exporter镜像
    docker pull prom/snmp-exporter
  2. 创建snmp.yml配置文件目录
    mkdir /home/samroot/exporter/snmp
  3. 手动创建snmp.yml配置文件,参考《2 SNMP Exporter介绍》章节中的snmp.yml示例文件
  4. 根据snmp exporter镜像创建容器
    docker create --name snmp_to_117 -v /home/samroot/exporter/snmp/:/etc/snmp_exporter/ -p 9116:9116 prom/snmp-exporter
  5. 启动容器
    docker container start snmp_to_117
  6. 检查容器运行情况
    docker container ps|grep snmp
    输出结果参考
    f06810ffa6d6 prom/snmp-exporter "/bin/snmp_exporter …" 8 days ago Up 3 days 0.0.0.0:9116->9116/tcp snmp_to_117
  7. 防火墙放通9116端口
    firewall-cmd --permanent --add-port=9116/tcp

3.3 http访问snmp exporter,查看暴露出来的监控数据

  1. 浏览器访问snmp exporter的http端口,输入被监控设备的IP地址和模块名称,点击Submit

  1. SNMP Exporter已经从被监控设备的SNMP Agent中获取到一些设备的运行状态

4 将收集到的数据存到Prometheus中

在Prometheus的配置文件中添加SNMP Exporter的地址,即可将收集到的数据存到Prometheus中。

  1. 修改prometheus配置文件prometheus.yml
  1. # Here it's Prometheus itself.
  2. scrape_configs:
  3. # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  4. - job_name: "prometheus"
  5. # metrics_path defaults to '/metrics'
  6. # scheme defaults to 'http'.
  7. static_configs:
  8. - targets: ["localhost:9090"]
  9. #采集snmp exporter监控数据
  10. - job_name: 'snmp'
  11. static_configs:
  12. - targets:
  13. - 192.168.1.117
  14. metrics_path: /snmp
  15. params:
  16. module: [Linux]
  17. relabel_configs:
  18. - source_labels: [__address__]
  19. target_label: __param_target
  20. - source_labels: [__param_target]
  21. target_label: instance
  22. - target_label: __address__
  23. replacement: 192.168.1.200:9116
  1. 使配置文件生效
    curl -XPOST http://localhost:9090/-/reload
  2. 确认Prometheus能够正常采集到snmp exporter的数据

5 配合Grafana实现可视化

  1. 配置dashboard的的名称和host变量:

  2. 新建plane,配置CPU使用率监控

  3. 保存退出 

6 参考文章

什么是SNMP:https://support.huawei.com/enterprise/zh/doc/EDOC1100087025

SNMP_Exporter:https://github.com/prometheus/snmp_exporter

 

原文链接:https://www.cnblogs.com/kernelry/p/17354637.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号