Skip to content

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

WRPStephanie
Copy link
Contributor

新增采集网络指标的collector

@Abingcbc Abingcbc requested a review from Copilot June 23, 2025 11:43
Copy link
Contributor

@Copilot Copilot AI left a 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 and GetNetRateInformationOnce to validate parsing logic against sample /proc/net data.
bool LinuxSystemInterface::GetTCPStatInformationOnce(TCPStatInformation& tcpStatInfo) {

@WRPStephanie WRPStephanie force-pushed the netmain branch 5 times, most recently from 8d188b7 to e6d0981 Compare June 27, 2025 08:05

class NetCollectorUnittest : public ::testing::Test {
public:
void TestCollect() const;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没有异常情况的单测。

  1. ReadSocketStat函数测试
    测试文件不存在的情况
    测试文件格式错误的情况
  2. GetInterfaceConfig函数测试
    测试网络接口不存在的情况
    测试IPv4/IPv6地址解析
  3. ReadNetLink函数测试
    测试netlink socket创建失败
    测试消息发送/接收失败
    测试TCP状态统计正确性
  4. 网络数据解析测试
    测试/proc/net/dev文件格式变化
    测试异常数据的处理
    测试数值转换异常

Copy link
Contributor Author

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)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有些地方是用CheckExistance,有些是用filesystem,是不是可以统一一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants