Skip to content

Commit

Permalink
fix connect to dev dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
naiba committed Oct 22, 2024
1 parent f0c2a7a commit fbf099e
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 60 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
/agent
/cmd/agent/agent
/cmd/agent/config.yml
*.pprof
dist
4 changes: 3 additions & 1 deletion cmd/agent/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import (
)

// 修改Agent要监控的网卡与硬盘分区
func editAgentConfig() {
func editAgentConfig(configPath string) {
agentConfig.Read(configPath)

nc, err := psnet.IOCounters(true)
if err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func main() {
}

if isEditConfig {
editAgentConfig()
editAgentConfig(configPath)
os.Exit(0)
}

Expand Down
58 changes: 58 additions & 0 deletions model/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package model

import (
"os"

"github.com/spf13/viper"
"sigs.k8s.io/yaml"
)

type AgentConfig struct {
Debug bool `mapstructure:"debug"`

Server string `mapstructure:"server"` // 服务器地址
ClientSecret string `mapstructure:"client_secret"` // 客户端密钥
UUID string `mapstructure:"uuid"`

HardDrivePartitionAllowlist []string `mapstructure:"hard_drive_partition_allowlist"`
NICAllowlist map[string]bool `mapstructure:"nic_allowlist"`
DNS []string `mapstructure:"dns"`
GPU bool `mapstructure:"gpu"` // 是否检查GPU
Temperature bool `mapstructure:"temperature"` // 是否检查温度
SkipConnectionCount bool `mapstructure:"skip_connection_count"` // 跳过连接数检查
SkipProcsCount bool `mapstructure:"skip_procs_count"` // 跳过进程数量检查
DisableAutoUpdate bool `mapstructure:"disable_auto_update"` // 关闭自动更新
DisableForceUpdate bool `mapstructure:"disable_force_update"` // 关闭强制更新
DisableCommandExecute bool `mapstructure:"disable_command_execute"` // 关闭命令执行
ReportDelay int `mapstructure:"report_delay"` // 报告间隔
TLS bool `mapstructure:"tls"` // 是否使用TLS加密传输至服务端
InsecureTLS bool `mapstructure:"insecure_tls"` // 是否禁用证书检查
UseIPv6CountryCode bool `mapstructure:"use_i_pv_6_country_code"` // 默认优先展示IPv6旗帜
UseGiteeToUpgrade bool `mapstructure:"use_gitee_to_upgrade"` // 强制从Gitee获取更新
IPReportPeriod uint32 `mapstructure:"ip_report_period"` // IP上报周期

v *viper.Viper
}

// Read 从给定的文件目录加载配置文件
func (c *AgentConfig) Read(path string) error {
c.v = viper.New()
c.v.SetConfigFile(path)
err := c.v.ReadInConfig()
if err != nil {
return err
}
err = c.v.Unmarshal(c)
if err != nil {
return err
}
return nil
}

func (c *AgentConfig) Save() error {
data, err := yaml.Marshal(c)
if err != nil {
return err
}
return os.WriteFile(c.v.ConfigFileUsed(), data, os.ModePerm)
}
58 changes: 0 additions & 58 deletions model/model.go

This file was deleted.

0 comments on commit fbf099e

Please sign in to comment.