Files

99 lines
1.8 KiB
Go

package cmd
import (
"agent-wdd/host_info"
"github.com/spf13/cobra"
)
func addInfoSubcommands(cmd *cobra.Command) {
// 操作系统
os := &cobra.Command{
Use: "os",
Short: "主机操作系统相关的信息",
Run: func(cmd *cobra.Command, args []string) {
os := host_info.ConfigCache.Agent.OS
os.Gather()
os.SaveConfig()
},
}
// network
network := &cobra.Command{
Use: "network",
Short: "主机Network相关的信息",
Run: func(cmd *cobra.Command, args []string) {
network := host_info.ConfigCache.Agent.Network
network.Gather()
network.SaveConfig()
},
}
// cpu
cpu := &cobra.Command{
Use: "cpu",
Short: "主机cpu相关的信息",
Run: func(cmd *cobra.Command, args []string) {
cpu := host_info.ConfigCache.Agent.CPU
cpu.Gather()
cpu.Save()
},
}
// memory
memory := &cobra.Command{
Use: "mem",
Short: "主机memory相关的信息",
Run: func(cmd *cobra.Command, args []string) {
mem := host_info.ConfigCache.Agent.Mem
mem.Gather()
swap := host_info.ConfigCache.Agent.Swap
swap.Gather()
mem.SaveConfig()
swap.SaveConfig()
},
}
// disk
disk := &cobra.Command{
Use: "disk",
Short: "主机disk相关的信息",
Run: func(cmd *cobra.Command, args []string) {
//disks := host_info.ConfigCache.Agent.Disks
host_info.DiskListGather()
host_info.DiskListSaveConfig()
},
}
// all全部的info
all := &cobra.Command{
Use: "all",
Short: "主机全部相关的信息",
Run: func(cmd *cobra.Command, args []string) {
// 执行所有info
cpu.Run(cmd, args)
os.Run(cmd, args)
memory.Run(cmd, args)
network.Run(cmd, args)
disk.Run(cmd, args)
// 归一化
host_info.ConfigCache.NormalizeConfig()
},
}
cmd.AddCommand(
all,
os,
cpu,
memory,
network,
disk,
)
}