package state

import (
	"nms_nbi/lib/log"

	"github.com/shirou/gopsutil/cpu"
	"github.com/shirou/gopsutil/disk"
	"github.com/shirou/gopsutil/host"
	"github.com/shirou/gopsutil/mem"
)

func getSystemInfo() {
	// 获取主机信息
	hostInfo, err := host.Info()
	if err != nil {
		log.Errorf("Failed to get host info: %v", err)
		return
	}
	log.Tracef("Host info: %+v", hostInfo)

	// 获取CPU信息
	cpuInfo, err := cpu.Info()
	if err != nil {
		log.Errorf("Failed to get CPU info: %v", err)
		return
	}
	log.Tracef("CPU info: %+v", cpuInfo)

	// 获取内存信息
	memInfo, err := mem.VirtualMemory()
	if err != nil {
		log.Errorf("Failed to get memory info: %v", err)
		return
	}
	log.Tracef("Memory info: %+v", memInfo)

	// 获取磁盘分区信息
	diskPartitions, err := disk.Partitions(true)
	if err != nil {
		log.Errorf("Failed to get disk partitions: %v", err)
		return
	}
	log.Tracef("Disk partitions: %+v", diskPartitions)
	for _, partition := range diskPartitions {
		// 获取每个磁盘分区的使用情况
		usage, err := disk.Usage(partition.Mountpoint)
		if err != nil {
			log.Errorf("Failed to get disk usage for %s: %v", partition.Mountpoint, err)
			continue
		}
		log.Tracef("%s usage: %+v", partition.Mountpoint, usage)
	}
}

func getCpuNumber() int {
	// 获取CPU信息
	cpuInfo, err := cpu.Info()
	if err != nil {
		log.Errorf("Failed to get CPU info: %v", err)
		return 0
	}
	log.Tracef("CPU info: %+v", cpuInfo)
	return len(cpuInfo)
}

func getTotalMemory() int {
	// 获取内存信息
	memInfo, err := mem.VirtualMemory()
	if err != nil {
		log.Errorf("Failed to get memory info: %v", err)
		return 0
	}
	log.Tracef("Memory info: %+v", memInfo)
	return int(memInfo.Total)
}
