使用Grafana+Prometheus监控网络设备
在Linux下安装Granfna+Prometheus集成环境通过snmp协议监控网络设备
安装前提
Granfa软件包
- Grafana官方地址:https://grafana.com/
- Grafana官方文档地址:https://grafana.com/docs/
- Grafana官方下载地址:https://grafana.com/grafana/download?pg=graf&plcmt=deploy-box-1
- Grafana官方模板地址:https://grafana.com/grafana/dashboards/
Prometheus软件包
- Prometheus官网:https://prometheus.io/
- Prometheus官方文档:https://prometheus.io/docs/introduction/overview/
- Prometheus官方下载地址:https://prometheus.io/download/
Prometheus snmp模块
- snmp_export模块下载:https://github.com/prometheus/snmp_exporter
安装配置
系统环境
操作系统版本:openEuler-22.03-LTS-SP3
中间件操作顺序:
- 配置snmp_exporter模块
- 配置prometheus采集数据
- 配置Grafana分析展示数据
snmp_exporter安装和配置
[root@localhost ~]# wget https://github.com/prometheus/snmp_exporter/releases/download/v0.24.1/snmp_exporter-0.24.1.linux-amd64.tar.gz
[root@localhost ~]# tar -zxvf snmp_exporter-0.24.1.linux-amd64.tar.gz
[root@localhost ~]# mv snmp_exporter-0.24.1.linux-amd64 /usr/local/prometheus/snmp_exporter
# 配置snmp信息
[root@localhost ~]# vi /usr/local/prometheus/snmp_exporter/snmp.yml
auths:
public_v2:
community: # 团体名
version: 2
modules:
if_mib:
walk:
- 1.3.6.1.2.1.2.2.1.10.2 #IPv4流入流量
- 1.3.6.1.2.1.2.2.1.16.2 #IPv4流出流量
get:
- 1.3.6.1.2.1.2.2.1
metrics:
- name: IPv4_ifOutOctets
oid: 1.3.6.1.2.1.2.2.1.16.2
type: gauge
- name: IPv4_ifInOctets
oid: 1.3.6.1.2.1.2.2.1.10.2
type: gauge
# 配置service文件
[root@localhost ~]# vi /usr/lib/systemd/system/snmp_exporter.service
[Unit]
Description=node_exporter
After=network.target
[Service]
ExecStart=/usr/local/prometheus/snmp_exporter/snmp_exporter --config.file=/usr/local/prometheus/snmp_exporter/snmp.yml
Restart=on-failure
[Install]
WantedBy=multi-user.target
# 配置服务生效并启动
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl start snmp_exporter
打开浏览器验证服务
http://172.16.1.14:9116/
Prometherus安装和配置
[root@localhost ~]# wget https://github.com/prometheus/prometheus/releases/download/v2.51.1/prometheus-2.51.1.linux-amd64.tar.gz
[root@localhost ~]# tar -zxvf prometheus-2.51.1.linux-amd64.tar.gz
[root@localhost ~]# mv prometheus-2.51.1.linux-amd64 /usr/local/prometheus
# 配置prometheus配置文件
[root@localhost ~]# mv prometheus.yml prometheus.yml.bak
[root@localhost ~]# vi prometheus.yml
- job_name: "Test"
static_configs:
- targets:
- 172.16.1.14 # 网管交换机的 IP 地址
metrics_path: /snmp
params:
module: [if_mib]
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: localhost:9116 # SNMP Exporter 的地址和端口
# 配置prometheus.service服务文件
[root@localhost ~]# vi /usr/lib/systemd/system/prometheus.service
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target
[Service]
WorkingDirectory=/usr/local/prometheus/
ExecStart=/usr/local/prometheus/prometheus
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=/bin/kill -KILL $MAINPID
Type=simple
KillMode=control-group
Restart=on-failure
RestartSec=15s
[Install]
WantedBy=multi-user.target
# 配置服务生效
systemctl daemon-reload
systemctl satrt prometheus
浏览器验证服务
http://172.16.1.14:9090/
这里显示为down是因为选定的主机没有配置snmp,各位博友可以自己尝试下
Grafana安装和配置
[root@localhost ~]# sudo yum install -y https://dl.grafana.com/enterprise/release/grafana-enterprise-10.4.1-1.x86_64.rpm
[root@localhost ~]# systemctl start grafana-server
Grafana安装很简单,直接启动后浏览器访问
http://172.16.1.14:3000/login
默认账号为:admin
默认密码为:admin
- 设置中文
- 对接Prometheus
- 成功连接如下: