-
Notifications
You must be signed in to change notification settings - Fork 421
feature: add net collector #2265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a new network metrics collector to the host monitoring system, adding both collection logic and unit tests, and wiring it into existing input and runner components.
- Added
NetCollector
class for gathering network interface and TCP connection statistics. - Extended
SystemInterface
(and its Linux implementation) with methods to fetch TCP and network-rate information. - Introduced
NetCollectorUnittest
and updated CMake to build and run the new test. - Registered
NetCollector
in input/plugin components (InputHostMonitor.cpp
,HostMonitorInputRunner.cpp
).
Reviewed Changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
core/host_monitor/collector/NetCollector.h | Declared new NetCollector API |
core/host_monitor/collector/NetCollector.cpp | Implemented network-stat parsing and reporting |
core/host_monitor/SystemInterface.{h,cpp} | Added GetTCPStatInformation* and GetNetRateInformation* |
core/host_monitor/LinuxSystemInterface.cpp | Parsed /proc/net/sockstat* and /proc/net/dev |
core/unittest/host_monitor/NetCollectorUnittest.cpp | Created unit tests for NetCollector |
Comments suppressed due to low confidence (1)
core/host_monitor/LinuxSystemInterface.cpp:411
- Consider adding unit tests for
GetTCPStatInformationOnce
andGetNetRateInformationOnce
to validate parsing logic against sample/proc/net
data.
bool LinuxSystemInterface::GetTCPStatInformationOnce(TCPStatInformation& tcpStatInfo) {
8d188b7
to
e6d0981
Compare
|
||
class NetCollectorUnittest : public ::testing::Test { | ||
public: | ||
void TestCollect() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没有异常情况的单测。
- ReadSocketStat函数测试
测试文件不存在的情况
测试文件格式错误的情况 - GetInterfaceConfig函数测试
测试网络接口不存在的情况
测试IPv4/IPv6地址解析 - ReadNetLink函数测试
测试netlink socket创建失败
测试消息发送/接收失败
测试TCP状态统计正确性 - 网络数据解析测试
测试/proc/net/dev文件格式变化
测试异常数据的处理
测试数值转换异常
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4. /proc/net/dev文件格式变化
已补充异常情况测试。读取的/proc/net/dev的内容长期保持不变,基本可以不考虑这种情况。
// ipv6 | ||
std::vector<std::string> netInet6Lines = {}; | ||
std::string errorMessage; | ||
if (std::filesystem::exists(PROCESS_DIR / PROCESS_NET_IF_INET6)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有些地方是用CheckExistance,有些是用filesystem,是不是可以统一一下
新增采集网络指标的collector