Loading... ## 温馨提示 <div class="tip inlineBlock warning"> OpenVPN 是企业建立虚拟专用网络的常用工具之一,适用于远程办公等场景。本文仅做技术研究,请勿将 OpenVPN 用于不合规用途(如跨境互联)! </div> <div class="tip inlineBlock error"> 将 OpenVPN 用于不合规用途(如跨境互联)会导致服务器端口被封禁!!! </div> ## 编译 openvpn_exporter ### 需要环境 go ### 编译 ```bash mkdir /usr/local/openvpn_exporter cd /usr/local/openvpn_exporter # 树莓派是 arm 架构的,这是编译 arm 架构的命令: GOARCH=arm go build github.com/kumina/openvpn_exporter # 正常编译使用这个命令: go build github.com/kumina/openvpn_exporter ``` ## 运行 创建 systemd 服务 `vim /etc/systemd/system/openvpn_exporter.service`,如果路径不同,需要修改下对应的路径 ```bash [Unit] Description=OpenVPN Exporter Service After=network.target [Service] User=prometheus ExecStart=/usr/local/openvpn_exporter/openvpn_exporter -openvpn.status_paths /etc/openvpn/openvpn-status.log -web.listen-address 0.0.0.0:9269 Restart=on-failure RestartPreventExitStatus=23 RestartSec=5 [Install] WantedBy=multi-user.target ``` 启动服务并设置开机启动 ```bash service openvpn_exporter start systemctl enable openvpn_exporter service openvpn_exporter status ``` 对 Prometheus Server 放行防火墙端口 ```bash iptables -A INPUT -s 需要访问exporter的IP段 -p tcp --dport 9269 -j ACCEPT -m comment --comment "prometheus-openvpn-exporter" ``` 访问 `http://IP:9269/metrics` 可看到指标 ## 接入 Prometheus Server 修改 Prometheus 配置 `vim /usr/local/prometheus/prometheus.yml`,在 scrape_configs 中增加 Job 和 Targets ``` - job_name: "openvpn" static_configs: # Rpi - targets: ["openvpn_exporter所在节点的IP地址:9269"] ``` ## Grafana 大盘 模版 https://grafana.com/grafana/dashboards/12140   最后修改:2024 年 08 月 01 日 © 允许规范转载 赞 如果觉得我的文章对你有用,请随意赞赏