[agent-go] [status] add status module

This commit is contained in:
zeaslity
2023-04-13 17:36:30 +08:00
parent 0a310145ed
commit 3dbba79203

View File

@@ -21,14 +21,6 @@ type NetworkInfo struct {
RecvRate string `json:"recv_rate,omitempty"`
}
func main() {
info, err := GetNetworkInfo()
if err != nil {
panic(err)
}
fmt.Printf("%+v\n", info)
}
func GetNetworkInfo() (*NetworkInfo, error) {
interfaces, err := net.Interfaces()
if err != nil {
@@ -46,7 +38,8 @@ func GetNetworkInfo() (*NetworkInfo, error) {
for _, addr := range mainInterface.Addrs {
allAddrs = append(allAddrs, addr.Addr)
}
ipv4List, ipv6List := GetIPAddresses(allAddrs)
ipv4List, ipv6List := GetInternelIpAddrs(allAddrs)
log.DebugF("ipv4 list are => %v, ipv4 list are => %v", ipv4List, ipv6List)
counters, err := net.IOCounters(true)
if err != nil {
@@ -106,7 +99,7 @@ func formatBytes(bytes uint64) string {
return fmt.Sprintf("%.1f %cB", float64(bytes)/float64(div), "KMGTPE"[exp])
}
func GetIPAddresses(addresses []string) ([]string, []string) {
func GetInternelIpAddrs(addresses []string) ([]string, []string) {
var ipv4 []string
var ipv6 []string
for _, addr := range addresses {