[Agent] [Status] network metric
This commit is contained in:
@@ -17,6 +17,9 @@ type NetworkMetric struct {
|
||||
RecvSpeed float64
|
||||
}
|
||||
|
||||
type NetworkInfo struct {
|
||||
}
|
||||
|
||||
type NetworkStatus struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
InternalIPv4 []string `json:"internal_ip_v4,omitempty"`
|
||||
@@ -49,16 +52,19 @@ func GetNetworkMetric() ([]NetworkMetric, error) {
|
||||
return nil, errors.New(233, msg)
|
||||
}
|
||||
|
||||
ioCountersStats, err := net.IOCounters(false)
|
||||
ioCountersStats, err := net.IOCounters(true)
|
||||
if err != nil {
|
||||
log.ErrorF("[GetNetworkMetric] - get io counter list error %v\n", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
//marshal, _ := json.Marshal(ioCountersStats)
|
||||
//fmt.Println(string(marshal))
|
||||
duration := time.Second * 2
|
||||
log.DebugF("[GetNetworkMetric] - start to wait %d seconds ", duration/1000000000)
|
||||
time.Sleep(duration)
|
||||
|
||||
afterIoCounterList, err := net.IOCounters(false)
|
||||
afterIoCounterList, err := net.IOCounters(true)
|
||||
if err != nil {
|
||||
log.ErrorF("[GetNetworkMetric] - get io counter list second error %v\n", err)
|
||||
return nil, err
|
||||
@@ -68,11 +74,11 @@ func GetNetworkMetric() ([]NetworkMetric, error) {
|
||||
|
||||
for _, interfaceStat := range interfaceStatList {
|
||||
if MatchNetInterfaceRight(interfaceStat.Name) {
|
||||
|
||||
log.DebugF("[GetNetworkMetric] - match net interface name is => %s", interfaceStat.Name)
|
||||
for _, after := range afterIoCounterList {
|
||||
if strings.Contains(after.Name, interfaceStat.Name) {
|
||||
if strings.HasPrefix(after.Name, interfaceStat.Name) {
|
||||
for _, before := range ioCountersStats {
|
||||
if strings.Contains(before.Name, interfaceStat.Name) {
|
||||
if strings.HasPrefix(before.Name, interfaceStat.Name) {
|
||||
// match after and before interface
|
||||
|
||||
// assign
|
||||
|
||||
Reference in New Issue
Block a user