Merge pull request #137 from CoiaPrant/master
修复LXC容器的读取内存和Swap错误 Co-authored-by: CoiaPrant <42506847+CoiaPrant@users.noreply.github.com>
This commit is contained in:
		
						commit
						b1a1178fe5
					
				@ -44,7 +44,6 @@ func GetHost() *model.Host {
 | 
				
			|||||||
		cpus = append(cpus, fmt.Sprintf("%s %d %s Core", model, count, cpuType))
 | 
							cpus = append(cpus, fmt.Sprintf("%s %d %s Core", model, count, cpuType))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	mv, _ := mem.VirtualMemory()
 | 
						mv, _ := mem.VirtualMemory()
 | 
				
			||||||
	ms, _ := mem.SwapMemory()
 | 
					 | 
				
			||||||
	diskTotal, _ := getDiskTotalAndUsed()
 | 
						diskTotal, _ := getDiskTotalAndUsed()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return &model.Host{
 | 
						return &model.Host{
 | 
				
			||||||
@ -52,7 +51,7 @@ func GetHost() *model.Host {
 | 
				
			|||||||
		PlatformVersion: hi.PlatformVersion,
 | 
							PlatformVersion: hi.PlatformVersion,
 | 
				
			||||||
		CPU:             cpus,
 | 
							CPU:             cpus,
 | 
				
			||||||
		MemTotal:        mv.Total,
 | 
							MemTotal:        mv.Total,
 | 
				
			||||||
		SwapTotal:       ms.Total,
 | 
							SwapTotal:       mv.SwapTotal,
 | 
				
			||||||
		DiskTotal:       diskTotal,
 | 
							DiskTotal:       diskTotal,
 | 
				
			||||||
		Arch:            hi.KernelArch,
 | 
							Arch:            hi.KernelArch,
 | 
				
			||||||
		Virtualization:  hi.VirtualizationSystem,
 | 
							Virtualization:  hi.VirtualizationSystem,
 | 
				
			||||||
@ -66,7 +65,6 @@ func GetHost() *model.Host {
 | 
				
			|||||||
func GetState() *model.HostState {
 | 
					func GetState() *model.HostState {
 | 
				
			||||||
	hi, _ := host.Info()
 | 
						hi, _ := host.Info()
 | 
				
			||||||
	mv, _ := mem.VirtualMemory()
 | 
						mv, _ := mem.VirtualMemory()
 | 
				
			||||||
	ms, _ := mem.SwapMemory()
 | 
					 | 
				
			||||||
	var cpuPercent float64
 | 
						var cpuPercent float64
 | 
				
			||||||
	cp, err := cpu.Percent(0, false)
 | 
						cp, err := cpu.Percent(0, false)
 | 
				
			||||||
	if err == nil {
 | 
						if err == nil {
 | 
				
			||||||
@ -75,8 +73,8 @@ func GetState() *model.HostState {
 | 
				
			|||||||
	_, diskUsed := getDiskTotalAndUsed()
 | 
						_, diskUsed := getDiskTotalAndUsed()
 | 
				
			||||||
	return &model.HostState{
 | 
						return &model.HostState{
 | 
				
			||||||
		CPU:            cpuPercent,
 | 
							CPU:            cpuPercent,
 | 
				
			||||||
		MemUsed:        mv.Used,
 | 
							MemUsed:        mv.Total - mv.Available,
 | 
				
			||||||
		SwapUsed:       ms.Used,
 | 
							SwapUsed:       mv.SwapTotal - mv.SwapFree,
 | 
				
			||||||
		DiskUsed:       diskUsed,
 | 
							DiskUsed:       diskUsed,
 | 
				
			||||||
		NetInTransfer:  atomic.LoadUint64(&netInTransfer),
 | 
							NetInTransfer:  atomic.LoadUint64(&netInTransfer),
 | 
				
			||||||
		NetOutTransfer: atomic.LoadUint64(&netOutTransfer),
 | 
							NetOutTransfer: atomic.LoadUint64(&netOutTransfer),
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user