[agent-wdd] 基本完成Info部分的整理

This commit is contained in:
zeaslity
2025-02-13 15:29:26 +08:00
parent e826b55240
commit dabf63f10f
13 changed files with 764 additions and 41 deletions

View File

@@ -18,17 +18,28 @@ func init() {
// 配置结构体定义
type Config struct {
TimeStamp string `yaml:"timestamp"`
Agent Agent `yaml:"agent"`
TimeStamp string `yaml:"timestamp"`
ModifiedTimes int `yaml:"modifiedTimes"`
Agent Agent `yaml:"agent"`
}
type Agent struct {
Hostname string `yaml:"hostname"`
Network Network `yaml:"network"`
CPU CPU `yaml:"cpu"`
Mem Memory `yaml:"mem"`
Swap Swap `yaml:"swap"`
Disk []Disk `yaml:"disk"`
OS OS `yaml:"os"`
Network Network `yaml:"network"`
CPU CPU `yaml:"cpu"`
Mem Memory `yaml:"mem"`
Swap Swap `yaml:"swap"`
Disks []Disk `yaml:"disks"`
}
type OS struct {
Hostname string `yaml:"hostname"`
OsName string `yaml:"os_name"`
OsFamily string `yaml:"os_family"`
OsVersion string `yaml:"os_version"`
OsType string `yaml:"os_type"`
Kernel string `yaml:"kernel"`
Arch string `yaml:"arch"`
}
type Network struct {
@@ -53,9 +64,12 @@ type Interface struct {
}
type CPU struct {
Cores int `yaml:"cores"`
Brand string `yaml:"brand"`
Mhz int `yaml:"mhz"`
Cores int `yaml:"cores"`
Brand string `yaml:"brand"`
Mhz string `yaml:"mhz"`
Arch string `yaml:"arch"`
Virt string `yaml:"virt"`
Hypervisor string `yaml:"hypervisor"`
}
type Memory struct {
@@ -65,7 +79,7 @@ type Memory struct {
}
type Swap struct {
On bool `yaml:"on"`
Open bool `yaml:"open"`
Size string `yaml:"size"`
}
@@ -74,8 +88,6 @@ type Disk struct {
Size string `yaml:"size"`
Usage string `yaml:"usage"`
Percent string `yaml:"percent"`
VG string `yaml:"vg"`
LV string `yaml:"lv"`
}
func InitConfig() {
@@ -109,6 +121,9 @@ func SaveConfig() {
// 每次写入新的时间
ConfigCache.TimeStamp = utils.CurrentTimeString()
// 每次增加修改文件的次数计数
ConfigCache.ModifiedTimes += 1
data, err := yaml.Marshal(&ConfigCache)
if err != nil {
log.Error("YAML序列化失败: %w", err)