[ Agent ] [ Status ] - network info
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package status
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/shirou/gopsutil/v3/net"
|
||||
@@ -103,6 +104,52 @@ func GetNetworkMetric() ([]NetworkMetric, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func GetNetworkInfo() {
|
||||
|
||||
interfaceStatList, err := net.Interfaces()
|
||||
if err != nil {
|
||||
log.ErrorF("[GetNetworkInfo] - get net interface list error %s", err.Error())
|
||||
}
|
||||
|
||||
for _, interfaceStat := range interfaceStatList {
|
||||
fmt.Println()
|
||||
marshal, _ := json.Marshal(interfaceStat)
|
||||
fmt.Println(string(marshal))
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
connections, _ := net.Connections("tcp4")
|
||||
for _, con := range connections {
|
||||
fmt.Println()
|
||||
marshal, _ := json.Marshal(con)
|
||||
fmt.Println(string(marshal))
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
protoCounters, err := net.ProtoCounters([]string{})
|
||||
if err != nil {
|
||||
log.ErrorF("[GetNetworkInfo] - get proto counter list error %s", err.Error())
|
||||
}
|
||||
for _, proto := range protoCounters {
|
||||
fmt.Println()
|
||||
marshal, _ := json.Marshal(proto)
|
||||
fmt.Println(string(marshal))
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
filterCounters, err := net.FilterCounters()
|
||||
if err != nil {
|
||||
log.ErrorF("[GetNetworkInfo] - get filter counter list error %s", err.Error())
|
||||
}
|
||||
for _, filter := range filterCounters {
|
||||
fmt.Println()
|
||||
marshal, _ := json.Marshal(filter)
|
||||
fmt.Println(string(marshal))
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func GetNetworkStatus() (*NetworkStatus, error) {
|
||||
interfaces, err := net.Interfaces()
|
||||
if err != nil {
|
||||
|
||||
@@ -6,21 +6,6 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetNetworkInfo(t *testing.T) {
|
||||
|
||||
networkInfo, err := GetNetworkStatus()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
marshalIndent, err := json.MarshalIndent(networkInfo, "", " ")
|
||||
if err != nil {
|
||||
fmt.Printf("error")
|
||||
}
|
||||
|
||||
fmt.Println(string(marshalIndent))
|
||||
}
|
||||
|
||||
func TestMatchNetInterfaceRight(t *testing.T) {
|
||||
interfaceNames := []string{"eth0", "eth1", "enp3s0", "wlan0", "lo", "ens12", "eno1", "asdas", "en0"}
|
||||
|
||||
@@ -44,3 +29,8 @@ func TestGetNetworkMetric(t *testing.T) {
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetNetworkInfo(t *testing.T) {
|
||||
GetNetworkInfo()
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user