10分钟上手uos-tc-exporter:从安装到获取TC指标的快速教程
10分钟上手uos-tc-exporter:从安装到获取TC指标的快速教程
【免费下载链接】uos-tc-exporterA Prometheus exporter for tc stats via netlink.项目地址: https://gitcode.com/openeuler/uos-tc-exporter
前往项目官网免费下载:https://ar.openeuler.org/ar/
uos-tc-exporter是一款基于Prometheus的Linux流量控制(TC)指标导出器,能够通过netlink接口高效收集队列规则(qdisc)和类(class)的统计信息,为网络流量监控提供关键数据支持。本教程将帮助你在10分钟内完成从安装到获取指标的全过程,轻松掌握网络流量监控的核心工具。
为什么选择uos-tc-exporter?
uos-tc-exporter作为openEuler社区的开源项目,具备以下核心优势:
- 全面监控能力:支持HTB、CBQ、FQ、CODEL等多种队列规则和类的监控
- 高效数据收集:基于netlink接口与内核TC子系统直接通信,性能优异
- Prometheus兼容:提供标准Prometheus指标格式,无缝集成监控生态
- 灵活配置选项:通过YAML配置文件自定义监控参数和服务设置
- 网络命名空间支持:可监控不同网络命名空间中的TC配置
- 内置保护机制:包含请求限流功能,保障服务稳定运行
快速安装指南
准备工作
在开始安装前,请确保你的系统满足以下要求:
- Linux内核版本3.10或更高
- Go 1.20或更高版本(用于编译)
- Git工具
- 具有sudo权限的用户
一键安装步骤
# 克隆仓库 git clone https://gitcode.com/openeuler/uos-tc-exporter cd uos-tc-exporter # 编译项目 make build # 安装到系统 sudo make install简单配置方法
uos-tc-exporter的配置文件采用YAML格式,默认位置为/etc/uos-exporter/tc-exporter.yaml。以下是基础配置示例:
# 服务监听配置 address: "127.0.0.1" port: 9062 metricsPath: "/metrics" # 日志配置 log: level: "info" logPath: "/var/log/tc-exporter.log" maxSize: "10MB" maxAge: "168h" # 7天 # 服务器配置 server: shutdownTimeout: "30s"你可以根据实际需求修改配置参数,如更改监听地址、端口或调整日志级别。
启动服务的两种方式
直接运行
sudo ./tc-exporter作为systemd服务运行(推荐)
# 启动服务 sudo systemctl start uos-tc-exporter # 设置开机自启 sudo systemctl enable uos-tc-exporter # 查看服务状态 sudo systemctl status uos-tc-exporter获取TC指标数据
服务启动后,你可以通过以下方式获取TC指标:
使用curl命令
curl http://localhost:9062/metrics示例指标展示
uos-tc-exporter提供的指标包括但不限于:
# Qdisc指标 tc_qdisc_bytes_total{device="eth0",qdisc="htb"} 6789012 tc_qdisc_packets_total{device="eth0",qdisc="htb"} 12345 tc_qdisc_drops_total{device="eth0",qdisc="htb"} 0 # Class指标 tc_class_bytes_total{device="eth0",class="htb"} 3456789 tc_class_packets_total{device="eth0",class="htb"} 5432这些指标涵盖了流量字节数、数据包数量、丢包数等关键网络性能参数。
集成Prometheus监控
要将uos-tc-exporter集成到Prometheus监控系统中,只需在Prometheus配置文件中添加以下内容:
scrape_configs: - job_name: 'tc-exporter' static_configs: - targets: ['localhost:9062'] scrape_interval: 15s支持的队列规则类型
uos-tc-exporter支持多种常见的Linux TC队列规则,包括:
- HTB(Hierarchical Token Bucket)
- CBQ(Class Based Queueing)
- HFSC(Hierarchical Fair Service Curve)
- FQ(Fair Queue)
- FQ_CODEL(Fair Queue with Controlled Delay)
- CODEL(Controlled Delay)
- PIE(Proportional Integral controller Enhanced)
- RED(Random Early Detection)
- CHOKE(CHOose and Keep for responsive flows)
完整的支持列表和技术细节可参考项目的设计文档。
常见问题解决
权限问题
如果启动时遇到权限不足的错误,请使用sudo运行或为二进制文件设置适当的capabilities:
sudo setcap CAP_NET_ADMIN+ep /usr/bin/uos-tc-exporter端口冲突
若提示端口被占用,可修改配置文件中的port参数,选择未被使用的端口。
调试模式
如需排查问题,可启用调试日志:
export LOG_LEVEL=debug sudo -E tc-exporter深入学习资源
- 项目源代码:uos-tc-exporter
- 设计文档:docs/design.md
- 配置示例:config/tc-exporter.yaml
- 指标收集实现:internal/metrics/
- TC客户端代码:internal/tc/
通过本教程,你已经掌握了uos-tc-exporter的基本安装、配置和使用方法。这个强大的工具将帮助你深入了解Linux系统的网络流量控制情况,为网络性能优化和故障排查提供有力支持。开始你的TC指标监控之旅吧!
【免费下载链接】uos-tc-exporterA Prometheus exporter for tc stats via netlink.项目地址: https://gitcode.com/openeuler/uos-tc-exporter
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考