初始化项目
This commit is contained in:
98
agent-wdd/cmd/Info.go
Normal file
98
agent-wdd/cmd/Info.go
Normal file
@@ -0,0 +1,98 @@
|
||||
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()
|
||||
network.SaveConfig()
|
||||
},
|
||||
}
|
||||
|
||||
// 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) {
|
||||
// 执行所有info
|
||||
cpu.Run(cmd, args)
|
||||
os.Run(cmd, args)
|
||||
memory.Run(cmd, args)
|
||||
network.Run(cmd, args)
|
||||
disk.Run(cmd, args)
|
||||
|
||||
// 归一化
|
||||
config.ConfigCache.NormalizeConfig()
|
||||
},
|
||||
}
|
||||
|
||||
cmd.AddCommand(
|
||||
all,
|
||||
os,
|
||||
cpu,
|
||||
memory,
|
||||
network,
|
||||
disk,
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user