最近又在研究普罗米修斯,一种开源的监控系统。打算与SNMP结合使用
关于普罗米修斯的介绍,网上有很多
https://www.cnblogs.com/cuiyubo/p/10981840.html

由于操作系统本身并不直接支持Prometheus,同时用户也无法通过直接从操作系统层面上提供对Prometheus的支持。因此,用户只能通过独立运行一个程序的方式,通过操作系统提供的相关接口,将系统的运行状态数据转换为可供Prometheus读取的监控数据。 除了Node Exporter以外,比如MySQL Exporter、Redis Exporter等都是通过这种方式实现的。 这些Exporter程序扮演了一个中间代理人的角色。

SNMP与普罗米修斯

两者之间的通信格式和协议都不相同,故不能直接通信,但是我们可以使用snmp_exporter。
snmp-exporter是prometheus官方开源的一款网络设备监控工具,从SNMP收集的信息,供Prometheus监控系统使用。它有两个部分。一个执行实际抓取的snmp-exporter和一个generator(它依赖于NetSNMP)创建供导出器使用的配置。
相关信息
1.prometheus: 监控系统,负责指标的收取和一些告警规则的定义
2.snmp-exporter: 用于通过snmp协议暴露交换机的相关指标
3.SNMP Exporter Config Generator: 此配置生成器使用NetSNMP解析MIB,并使用它们为snmp_exporter生成配置–帮助生成snmp的配置文件
4.MIB和OID: MIB是管理信息库的缩写,它是用于管理通信网络中的实体的数据库。数据库是分层的(树形结构),并且每个条目都通过对象标识符(OID)进行寻址
5.snmp协议: SNMP 是专门设计用于在 IP 网络管理网络节点(服务器、工作站、路由器、交换机及HUBS等)的一种标准协议

普罗米修斯安装步骤
安装包下载
1.安装包github下载
https://prometheus.io/download/
2 安装

  • 1.部署到/usr/local/目录 tar -zxvf prometheus-2.23.0.linux-amd64.tar.gz -C /usr/local/
    2.修改文件夹名称 mv prometheus-2.23.0.linux-amd64 prometheus
    3.验证,查看版本号 cd prometheus/ ./prometheus --version

3 启动
使用Prometheus默认配置启动
/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml &
验证,打开浏览器访问9090端口
http://10.10.10.101:9090

关闭防火墙
/sbin/iptables -P INPUT ACCEPT
然后执行
/sbin/iptables -F
如果网页上提示

Warning: Error fetching server time: Detected 28799.773000001907 seconds time difference between your browser and the server. Prometheus relies on accurate time and time drift might cause unexpected query results.

更改一下系统时间和时区。
如果启动普罗米修斯 一直打印

msg="Error on ingesting samples that are too old or are too far into the future" num_dropped=332

需要删除安装目录下的data目录,重新启动
rm data/ -rf

4 监控NODE_EXRORTER节点
修改 prometheus 配置文件
/usr/local/prometheus/prometheus.yml:

global: 
scrape_interval: 15s 
evaluation_interval: 15s 
alerting: 
alertmanagers: 
- static_configs: 

- targets: ["localhost:9093"] 
rule_files: 
#- "alert.rules" 
scrape_configs: 
- job_name: 'prometheus' 
scrape_interval: 5s 
static_configs: 
- targets: ['localhost:9090'] 
- job_name: 'node' 
scrape_interval: 10s 
static_configs: 
- targets: ['localhost:9100']

完整 prometheus 配置文件可以参见:
https://github.com/yeaheo/prometheus-huang/blob/master/config/prometheus/prometheus.yml

5. 监控SNMP_EXRORTER节点
在prometheus 配置文件添加

- job_name: 'snmp'
    scrape_interval: 10s
    static_configs:
     - targets:
       - 10.10.10.101  # 交换机IP地址
    metrics_path: /snmp
    # params:
     # module: [if_mib]    #generator.yml或SNMP_EXRORTER配置文件中对应的模块
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 10.10.10.101:9116 # snmp_exporter 服务IP地址

6.NODE_EXRORTER下载安装步骤

  • 1安装包下载 https://prometheus.io/ 2 安装
    1.部署到/usr/local/目录 tar -zxvf node_exporter-1.0.1.linux-amd64.tar.gz -C /usr/local/
    2.修改文件夹名称 mv node_exporter-1.0.1.linux-amd64 node_exporter
    3.启动 使用默认配置启动 ./node_exporter
    4.验证,打开浏览器访问9100端口 http://10.10.10.101:9100

7.SNMP_EXRORTER下载安装步骤

  • SNMP-exporter下载地址
    https://github.com/prometheus/snmp_exporter/releases 2
    SNMP-exporter安装步骤 解压安装包 tar -zvxf
    snmp_exporter-0.19.0.linux-amd64.tar.gz -C /usr/local/ mv
    snmp_exporter-0.19.0.linux-amd64/ snmp_exporter 3配置snmp_exporter
    snmp_exporter的配置文件需要自己通过SNMP Exporter Config Generator 项目编译生成,

参考方法:
https://github.com/prometheus/snmp_exporter/tree/master/generator#file-format
由于Prometheus使用go语言开发的,所以自己编译生成snmp_exporter的配置文件需要go环境,Linux中安装go环境可参考:https://www.cnblogs.com/guoxiangyue/p/11772717.html 中安装go环境章节 建议安装较新的版本 因为老的版本没有context包 https://golang.org/doc/install
go环境安装以后,构建snmp exporter config Generator,执行以下操作:

#  apt-get -y install git
#  apt-get -y install gcc gcc-g++ make net-snmp net-snmp-utils net-snmp-libs net-snmp-devel
#export GOPATH=/home/guanchuang/gocode
#  go get github.com/prometheus/snmp_exporter/generator
#  cd ${GOPATH-$HOME/go}/src/github.com/prometheus/snmp_exporter/generator
#  go build
#  make mibs

执行完上述步骤后,在当前目录下会出现mibs文件夹,里面是下载好的一些mib文件。如果有些oid树是厂家自定义的,则要求厂家提供mib库文件(注意mib文件中,name不能为中文)并放到mibs目录下,
如自定义mib私有库则需要更改generator.yml
vim generator.yml 修改后,修改后的文件内容如下:

modules:
ns:
    walk:
      - 1.3.6.1.4.1.88888.1.1.10
    version: 2
    max_repetitions: 25
    retries: 3
timeout: 10s

执行以下操作,生成新的 snmp.yml 文件

#   export MIBDIRS=mibs
#   ./generator generate

将新生成的snmp.yml 替换掉原snmp_exporter中的snmp.yml

#   cp snmp.yml /usr/local/snmp_exporter

验证并设置snmp_exporter 服务开机启动

#   cd /usr/local/snmp_exporter
#   ./snmp_exporter

开启服务端口在9116上,浏览器访问 http://10.10.10.101:9116 , 在 Target 输入框中填入交换机IP地址,点击 submit 按钮,出现数据,在snmp_exporter 配置成功。

8.grafana下载安装步骤
官方下载地址: https://grafana.com/grafana/download
解压安装
tar -xvf grafana-7.3.6.linux-amd64.tar.gz -C /usr/local
进入安装目录bin目录下执行
./grafana-server
关于grafana的使用还在摸索

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐