Skip to content

Conversation

@WRPStephanie
Copy link
Contributor

新增采集网络指标的collector

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

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的内容长期保持不变,基本可以不考虑这种情况。

@yyuuttaaoo yyuuttaaoo merged commit cb7ba6b into alibaba:main Jul 25, 2025
17 checks passed
WRPStephanie added a commit to WRPStephanie/loongcollector that referenced this pull request Aug 6, 2025
* open/main: (27 commits)
  fix bug (alibaba#2329)
  doc: benchmark report (alibaba#2331)
  feat: modify CPU collector (alibaba#2296)
  Feat: Add alarm level (alibaba#2319)
  fix:  potenial zoombie cgo objects risk on windows platform (alibaba#2304)
  Optimize k8s meta protobuf transport (alibaba#2326)
  feat: networkobserver support multi configs  (alibaba#2298)
  minor: use reference in CollectionPipelineManager (alibaba#2323)
  use unified epoll to obtain data for various eBPF plugins (alibaba#2315)
  add type check when the config changes (alibaba#2314)
  feature: add net collector (alibaba#2265)
  feat:Add KafkaSerializer with unit tests (alibaba#2297)
  update k8s meta: add k8s.node link to infra.server, only standalone p… (alibaba#2306)
  fix: k8s meta input (alibaba#2309)
  fix: HashKeys are not used when converting data (alibaba#2311) (alibaba#2312)
  feat: add file security events collection (alibaba#2292)
  add cursor ignore (alibaba#2313)
  test: add disk chaos injection in e2e engine (alibaba#2280)
  fix: grpc find_package link ssl so (alibaba#2308)
  Upgrade the development image version and add the cpu instruction set check script (alibaba#2301)
  ...
ChaoEcho pushed a commit to ChaoEcho/loongcollector that referenced this pull request Aug 21, 2025
* feature: add net collector

* fix net ut

* fix net collector and add m label in system collector
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.

4 participants