🎨 CPU display
This commit is contained in:
		
							parent
							
								
									b46216fe5d
								
							
						
					
					
						commit
						86712e93a5
					
				@ -1,6 +1,10 @@
 | 
				
			|||||||
package model
 | 
					package model
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import pb "github.com/p14yground/nezha/proto"
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pb "github.com/p14yground/nezha/proto"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
	_ = iota
 | 
						_ = iota
 | 
				
			||||||
@ -56,9 +60,9 @@ type Host struct {
 | 
				
			|||||||
	Platform        string
 | 
						Platform        string
 | 
				
			||||||
	PlatformVersion string
 | 
						PlatformVersion string
 | 
				
			||||||
	CPU             []string
 | 
						CPU             []string
 | 
				
			||||||
	MemTotal       uint64
 | 
						MemTotal        uint64
 | 
				
			||||||
	DiskTotal      uint64
 | 
						DiskTotal       uint64
 | 
				
			||||||
	SwapTotal      uint64
 | 
						SwapTotal       uint64
 | 
				
			||||||
	Arch            string
 | 
						Arch            string
 | 
				
			||||||
	Virtualization  string
 | 
						Virtualization  string
 | 
				
			||||||
	BootTime        uint64
 | 
						BootTime        uint64
 | 
				
			||||||
@ -73,9 +77,9 @@ func (h *Host) PB() *pb.Host {
 | 
				
			|||||||
		Platform:        h.Platform,
 | 
							Platform:        h.Platform,
 | 
				
			||||||
		PlatformVersion: h.PlatformVersion,
 | 
							PlatformVersion: h.PlatformVersion,
 | 
				
			||||||
		Cpu:             h.CPU,
 | 
							Cpu:             h.CPU,
 | 
				
			||||||
		MemTotal:       h.MemTotal,
 | 
							MemTotal:        h.MemTotal,
 | 
				
			||||||
		DiskTotal:      h.DiskTotal,
 | 
							DiskTotal:       h.DiskTotal,
 | 
				
			||||||
		SwapTotal:      h.SwapTotal,
 | 
							SwapTotal:       h.SwapTotal,
 | 
				
			||||||
		Arch:            h.Arch,
 | 
							Arch:            h.Arch,
 | 
				
			||||||
		Virtualization:  h.Virtualization,
 | 
							Virtualization:  h.Virtualization,
 | 
				
			||||||
		BootTime:        h.BootTime,
 | 
							BootTime:        h.BootTime,
 | 
				
			||||||
@ -85,16 +89,27 @@ func (h *Host) PB() *pb.Host {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
// PB2Host ...
 | 
					// PB2Host ...
 | 
				
			||||||
func PB2Host(h *pb.Host) Host {
 | 
					func PB2Host(h *pb.Host) Host {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						cpuCount := make(map[string]int, 0)
 | 
				
			||||||
 | 
						cpus := h.GetCpu()
 | 
				
			||||||
 | 
						for _, u := range cpus {
 | 
				
			||||||
 | 
							cpuCount[u]++
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var distCpu []string
 | 
				
			||||||
 | 
						for u, num := range cpuCount {
 | 
				
			||||||
 | 
							distCpu = append(distCpu, fmt.Sprintf("%sx%d", u, num))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return Host{
 | 
						return Host{
 | 
				
			||||||
		Platform:        h.GetPlatform(),
 | 
							Platform:        h.GetPlatform(),
 | 
				
			||||||
		PlatformVersion: h.GetPlatformVersion(),
 | 
							PlatformVersion: h.GetPlatformVersion(),
 | 
				
			||||||
		CPU:             h.GetCpu(),
 | 
							CPU:             distCpu,
 | 
				
			||||||
		MemTotal:       h.GetMemTotal(),
 | 
							MemTotal:        h.GetMemTotal(),
 | 
				
			||||||
		DiskTotal:      h.GetDiskTotal(),
 | 
							DiskTotal:       h.GetDiskTotal(),
 | 
				
			||||||
		SwapTotal:      h.GetSwapTotal(),
 | 
							SwapTotal:       h.GetSwapTotal(),
 | 
				
			||||||
		Arch:            h.GetArch(),
 | 
							Arch:            h.GetArch(),
 | 
				
			||||||
		Virtualization:  h.GetVirtualization(),
 | 
							Virtualization:  h.GetVirtualization(),
 | 
				
			||||||
		BootTime:        h.GetBootTime(),
 | 
							BootTime:        h.GetBootTime(),
 | 
				
			||||||
@ -103,6 +118,3 @@ func PB2Host(h *pb.Host) Host {
 | 
				
			|||||||
		Version:         h.GetVersion(),
 | 
							Version:         h.GetVersion(),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
				
			|||||||
@ -23,7 +23,7 @@
 | 
				
			|||||||
                                class='arrow alternate circle down outline icon'></i>@#formatByteSize(server.State.NetInTransfer)#@<i
 | 
					                                class='arrow alternate circle down outline icon'></i>@#formatByteSize(server.State.NetInTransfer)#@<i
 | 
				
			||||||
                                class='arrow alternate circle up outline icon'></i>@#formatByteSize(server.State.NetOutTransfer)#@<br>
 | 
					                                class='arrow alternate circle up outline icon'></i>@#formatByteSize(server.State.NetOutTransfer)#@<br>
 | 
				
			||||||
                            启动:@# formatTimestamp(server.Host.BootTime) #@<br>
 | 
					                            启动:@# formatTimestamp(server.Host.BootTime) #@<br>
 | 
				
			||||||
                            版本:@#'v'+server.Host.Version#@<br>
 | 
					                            版本:@#server.Host.Version#@<br>
 | 
				
			||||||
                        </div>
 | 
					                        </div>
 | 
				
			||||||
                    </div>
 | 
					                    </div>
 | 
				
			||||||
                    <div class="description">
 | 
					                    <div class="description">
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user