diff --git a/cmd/agent/edit.go b/cmd/agent/edit.go index 157e990..0067318 100644 --- a/cmd/agent/edit.go +++ b/cmd/agent/edit.go @@ -80,9 +80,9 @@ func editAgentConfig(cmd *cobra.Command, args []string) { }, }, { - Name: "slient", + Name: "debug", Prompt: &survey.Confirm{ - Message: "是否禁用日志输出?", + Message: "是否开启调试模式?", Default: false, }, }, @@ -94,7 +94,7 @@ func editAgentConfig(cmd *cobra.Command, args []string) { DNS string GPU bool Temperature bool - Slient bool + Debug bool }{} err = survey.Ask(qs, &answers, survey.WithValidator(survey.Required)) @@ -134,7 +134,7 @@ func editAgentConfig(cmd *cobra.Command, args []string) { agentConfig.GPU = answers.GPU agentConfig.Temperature = answers.Temperature - agentConfig.Slient = answers.Slient + agentConfig.Debug = answers.Debug if err = agentConfig.Save(); err != nil { panic(err) diff --git a/cmd/agent/main.go b/cmd/agent/main.go index 0ab076d..73ef869 100644 --- a/cmd/agent/main.go +++ b/cmd/agent/main.go @@ -45,7 +45,6 @@ type AgentCliParam struct { DisableAutoUpdate bool // 关闭自动更新 DisableForceUpdate bool // 关闭强制更新 DisableCommandExecute bool // 关闭命令执行 - Debug bool // debug模式 Server string // 服务器地址 ClientSecret string // 客户端密钥 ReportDelay int // 报告间隔 @@ -53,7 +52,7 @@ type AgentCliParam struct { InsecureTLS bool // 是否禁用证书检查 Version bool // 当前版本号 IPReportPeriod uint32 // 上报IP间隔 - UseIPv6CountryCode bool // 默认优先展示IPv6旗帜 + UseIPv6CountryCode bool // 默认优先展示IPv6旗帜 } var ( @@ -143,7 +142,7 @@ func init() { agentCmd.PersistentFlags().StringVarP(&agentCliParam.ClientSecret, "password", "p", "", "Agent连接Secret") agentCmd.PersistentFlags().BoolVar(&agentCliParam.TLS, "tls", false, "启用SSL/TLS加密") agentCmd.PersistentFlags().BoolVarP(&agentCliParam.InsecureTLS, "insecure", "k", false, "禁用证书检查") - agentCmd.PersistentFlags().BoolVarP(&agentCliParam.Debug, "debug", "d", false, "开启调试信息") + agentCmd.PersistentFlags().BoolVarP(&agentConfig.Debug, "debug", "d", false, "开启调试信息") agentCmd.PersistentFlags().IntVar(&agentCliParam.ReportDelay, "report-delay", 1, "系统状态上报间隔") agentCmd.PersistentFlags().BoolVar(&agentCliParam.SkipConnectionCount, "skip-conn", false, "不监控连接数") agentCmd.PersistentFlags().BoolVar(&agentCliParam.SkipProcsCount, "skip-procs", false, "不监控进程数") @@ -154,7 +153,6 @@ func init() { agentCmd.PersistentFlags().BoolVar(&agentConfig.GPU, "gpu", false, "启用GPU监控") agentCmd.PersistentFlags().BoolVar(&agentConfig.Temperature, "temperature", false, "启用温度监控") agentCmd.PersistentFlags().Uint32VarP(&agentCliParam.IPReportPeriod, "ip-report-period", "u", 30*60, "本地IP更新间隔, 上报频率依旧取决于report-delay的值") - agentCmd.Flags().BoolVarP(&agentConfig.Slient, "slient", "q", false, "关闭日志输出") agentCmd.Flags().BoolVarP(&agentCliParam.Version, "version", "v", false, "查看当前版本号") agentConfig.Read(filepath.Dir(ex) + "/config.yml") @@ -223,7 +221,7 @@ func run() { // 上报服务器信息 go reportState() // 更新IP信息 - go monitor.UpdateIP(agentConfig.Slient, agentCliParam.UseIPv6CountryCode, agentCliParam.IPReportPeriod) + go monitor.UpdateIP(agentConfig.Debug, agentCliParam.UseIPv6CountryCode, agentCliParam.IPReportPeriod) // 定时检查更新 if _, err := semver.Parse(version); err == nil && !agentCliParam.DisableAutoUpdate { @@ -712,9 +710,7 @@ func handleTerminalTask(task *pb.Task) { } func println(v ...interface{}) { - if agentCliParam.Debug { - util.Println(agentConfig.Slient, v...) - } + util.Println(agentConfig.Debug, v...) } func generateQueue(start int, size int) []int { diff --git a/cmd/agent/service.go b/cmd/agent/service.go index 41af0f5..d87c210 100644 --- a/cmd/agent/service.go +++ b/cmd/agent/service.go @@ -79,7 +79,7 @@ func serviceActions(cmd *cobra.Command, args []string) { {agentCliParam.Server != "localhost:5555", "-s", agentCliParam.Server}, {agentCliParam.ClientSecret != "", "-p", agentCliParam.ClientSecret}, {agentCliParam.TLS, "--tls", ""}, - {agentCliParam.Debug, "-d", ""}, + {agentConfig.Debug, "-d", ""}, {agentCliParam.ReportDelay != 1, "--report-delay", fmt.Sprint(agentCliParam.ReportDelay)}, {agentCliParam.SkipConnectionCount, "--skip-conn", ""}, {agentCliParam.SkipProcsCount, "--skip-procs", ""}, diff --git a/model/model.go b/model/model.go index 0341b6a..628c86c 100644 --- a/model/model.go +++ b/model/model.go @@ -13,7 +13,7 @@ type AgentConfig struct { DNS []string GPU bool Temperature bool - Slient bool + Debug bool v *viper.Viper } diff --git a/pkg/monitor/monitor.go b/pkg/monitor/monitor.go index 18efb5b..9b1cee1 100644 --- a/pkg/monitor/monitor.go +++ b/pkg/monitor/monitor.go @@ -413,5 +413,5 @@ func atomicStoreFloat64(x *uint64, v float64) { } func println(v ...interface{}) { - util.Println(agentConfig.Slient, v...) + util.Println(agentConfig.Debug, v...) } diff --git a/pkg/util/util.go b/pkg/util/util.go index 8c493f2..92cad29 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -19,8 +19,8 @@ func IsWindows() bool { return os.PathSeparator == '\\' && os.PathListSeparator == ';' } -func Println(disabled bool, v ...interface{}) { - if !disabled { +func Println(enabled bool, v ...interface{}) { + if enabled { if runtime.GOOS != "darwin" { Logger.Infof("NEZHA@%s>> %v", time.Now().Format("2006-01-02 15:04:05"), fmt.Sprint(v...)) } else {