adjust linux network speed monitor
This commit is contained in:
		
							parent
							
								
									dae84c0a85
								
							
						
					
					
						commit
						1333eb85bb
					
				| @ -1,3 +1,4 @@ | |||||||
|  | //go:build !windows | ||||||
| // +build !windows | // +build !windows | ||||||
| 
 | 
 | ||||||
| package staros | package staros | ||||||
| @ -67,7 +68,13 @@ func NetSpeeds(duration time.Duration) ([]NetSpeed, error) { | |||||||
| 	for k, v := range list1 { | 	for k, v := range list1 { | ||||||
| 		recv := float64(list2[k].RecvBytes-v.RecvBytes) / duration.Seconds() | 		recv := float64(list2[k].RecvBytes-v.RecvBytes) / duration.Seconds() | ||||||
| 		send := float64(list2[k].SendBytes-v.SendBytes) / duration.Seconds() | 		send := float64(list2[k].SendBytes-v.SendBytes) / duration.Seconds() | ||||||
| 		res = append(res, NetSpeed{v.Name, recv, send}) | 		res = append(res, NetSpeed{ | ||||||
|  | 			Name:       v.Name, | ||||||
|  | 			RecvSpeeds: recv, | ||||||
|  | 			SendSpeeds: send, | ||||||
|  | 			RecvBytes:  list2[k].RecvBytes, | ||||||
|  | 			SendBytes:  list2[k].SendBytes, | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| 	return res, nil | 	return res, nil | ||||||
| } | } | ||||||
| @ -87,12 +94,12 @@ func NetSpeedsByName(duration time.Duration, name string) (NetSpeed, error) { | |||||||
| 
 | 
 | ||||||
| // NetConnections return all TCP/UDP/UNIX DOMAIN SOCKET Connections | // NetConnections return all TCP/UDP/UNIX DOMAIN SOCKET Connections | ||||||
| // if your uid != 0 ,and analysePid==true ,you should have CAP_SYS_PRTACE and CAP_DAC_OVERRIDE/CAP_DAC_READ_SEARCH Caps | // if your uid != 0 ,and analysePid==true ,you should have CAP_SYS_PRTACE and CAP_DAC_OVERRIDE/CAP_DAC_READ_SEARCH Caps | ||||||
| func NetConnections(analysePid bool,types string) ([]NetConn, error) { | func NetConnections(analysePid bool, types string) ([]NetConn, error) { | ||||||
| 	var result []NetConn | 	var result []NetConn | ||||||
| 	var inodeMap map[string]int64 | 	var inodeMap map[string]int64 | ||||||
| 	var err error | 	var err error | ||||||
| 	var fileList []string | 	var fileList []string | ||||||
| 	if types=="" || strings.Contains(strings.ToLower(types),"all") { | 	if types == "" || strings.Contains(strings.ToLower(types), "all") { | ||||||
| 		fileList = []string{ | 		fileList = []string{ | ||||||
| 			"/proc/net/tcp", | 			"/proc/net/tcp", | ||||||
| 			"/proc/net/tcp6", | 			"/proc/net/tcp6", | ||||||
| @ -101,14 +108,14 @@ func NetConnections(analysePid bool,types string) ([]NetConn, error) { | |||||||
| 			"/proc/net/unix", | 			"/proc/net/unix", | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	if strings.Contains(strings.ToLower(types),"tcp") { | 	if strings.Contains(strings.ToLower(types), "tcp") { | ||||||
| 		fileList =append(fileList,"/proc/net/tcp","/proc/net/tcp6") | 		fileList = append(fileList, "/proc/net/tcp", "/proc/net/tcp6") | ||||||
| 	} | 	} | ||||||
| 	if strings.Contains(strings.ToLower(types),"udp") { | 	if strings.Contains(strings.ToLower(types), "udp") { | ||||||
| 		fileList =append(fileList,"/proc/net/udp","/proc/net/udp6") | 		fileList = append(fileList, "/proc/net/udp", "/proc/net/udp6") | ||||||
| 	} | 	} | ||||||
| 	if strings.Contains(strings.ToLower(types),"unix") { | 	if strings.Contains(strings.ToLower(types), "unix") { | ||||||
| 		fileList =append(fileList,"/proc/net/unix") | 		fileList = append(fileList, "/proc/net/unix") | ||||||
| 	} | 	} | ||||||
| 	if analysePid { | 	if analysePid { | ||||||
| 		inodeMap, err = GetInodeMap() | 		inodeMap, err = GetInodeMap() | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user