refactor(agent): 简化CLI——去掉-p/-D flag,改用子命令 output/discover
- ./aiops-agent output → Zabbix风格输出全部上报指标(与API一致,含Heartbeat) - ./aiops-agent discover → Zabbix LLD端口发现JSON - ./aiops-agent -server URL → 正常采集模式(不变) - runOutput 构建与 collectAndReport 完全相同的 Report 结构体 - 新增 net.tcp.close_wait 采集(解析/proc/net/tcp state=08) - 静态编译 (CGO_ENABLED=0) 兼容 Alpine 容器
This commit is contained in:
1 parent
d656520428
commit
ad714c49f1
3 files changed
+249
-40
No files matched your search
@@ -44,6 +44,7 @@ func (c *NetworkCollector) Collect() (model.NetworkStat, error) {
|
||||
stat.TCPTimeWait = tcpStat.timeWait
|
||||
stat.TCPTotal = tcpStat.total
|
||||
}
|
||||
stat.TCPCloseWait = countCloseWait()
|
||||
|
||||
// 2. 采集网卡流量(取所有非 lo 网卡合计)
|
||||
curRx, curTx, nicName, err := readNetDevTotal()
|
||||
@@ -169,3 +170,21 @@ func readNetDevTotal() (rxBytes, txBytes uint64, nicName string, err error) {
|
||||
|
||||
return rxBytes, txBytes, nicName, scanner.Err()
|
||||
}
|
||||
|
||||
// countCloseWait 从 /proc/net/tcp 统计 CLOSE_WAIT 连接数
|
||||
func countCloseWait() int {
|
||||
count := 0
|
||||
for _, path := range []string{"/proc/net/tcp", "/proc/net/tcp6"} {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
for _, line := range strings.Split(string(data), "\n") {
|
||||
fields := strings.Fields(line)
|
||||
if len(fields) >= 4 && fields[3] == "08" {
|
||||
count++
|
||||
}
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
Reference in new issue
Block a user