Files
ProjectOctopus/agent-wdd/cmd/Info.go
2025-02-13 15:29:26 +08:00

93 lines
1.7 KiB
Go

package cmd
import (
"agent-wdd/config"
"github.com/spf13/cobra"
)
func addInfoSubcommands(cmd *cobra.Command) {
// 操作系统
os := &cobra.Command{
Use: "os",
Short: "主机操作系统相关的信息",
Run: func(cmd *cobra.Command, args []string) {
os := config.ConfigCache.Agent.OS
os.Gather()
os.SaveConfig()
},
}
// network
network := &cobra.Command{
Use: "network",
Short: "主机Network相关的信息",
Run: func(cmd *cobra.Command, args []string) {
network := config.ConfigCache.Agent.Network
network.Gather()
},
}
// cpu
cpu := &cobra.Command{
Use: "cpu",
Short: "主机cpu相关的信息",
Run: func(cmd *cobra.Command, args []string) {
cpu := config.ConfigCache.Agent.CPU
cpu.Gather()
cpu.Save()
},
}
// memory
memory := &cobra.Command{
Use: "mem",
Short: "主机memory相关的信息",
Run: func(cmd *cobra.Command, args []string) {
mem := config.ConfigCache.Agent.Mem
mem.Gather()
swap := config.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 := config.ConfigCache.Agent.Disks
config.DiskListGather()
config.DiskListSaveConfig()
},
}
// all全部的info
all := &cobra.Command{
Use: "all",
Short: "主机全部相关的信息",
Run: func(cmd *cobra.Command, args []string) {
cpu.Run(cmd, args)
os.Run(cmd, args)
memory.Run(cmd, args)
network.Run(cmd, args)
disk.Run(cmd, args)
},
}
cmd.AddCommand(
all,
os,
cpu,
memory,
network,
disk,
)
}