nezhahq-agent/pkg/monitor/conn/conn_fallback.go
UUBulb af41e4d843
modularize monitor, reduce init usage (#81)
* kill process tree using syscall on windows & cleanup (#80)

* kill process tree using syscall on windows & cleanup

* use job api

* add error check for cmd.Start

* modularize monitor, reduce init usage

* replace slices with sort

* update gopsutil & other dependencies
2024-11-03 21:53:09 +08:00

27 lines
445 B
Go

//go:build !linux
package conn
import (
"context"
"syscall"
"github.com/shirou/gopsutil/v4/net"
)
func GetState(_ context.Context) ([]uint64, error) {
var tcpConnCount, udpConnCount uint64
conns, _ := net.Connections("all")
for i := 0; i < len(conns); i++ {
switch conns[i].Type {
case syscall.SOCK_STREAM:
tcpConnCount++
case syscall.SOCK_DGRAM:
udpConnCount++
}
}
return []uint64{tcpConnCount, udpConnCount}, nil
}