Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var RootCmd = &cobra.Command{ Use: release.NAME, Short: "Circonus Host Agent", Long: `The Circonus host agent daemon provides a simple mechanism to expose systems and application metrics to Circonus. It inventories all executable programs in its plugin directory and executes them upon external request, returning results in JSON format.`, PersistentPreRunE: func(cmd *cobra.Command, args []string) error { if viper.GetBool(config.KeyLogPretty) { log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stdout}) } if viper.GetBool(config.KeyDebug) { viper.Set(config.KeyLogLevel, "debug") zerolog.SetGlobalLevel(zerolog.DebugLevel) log.Debug().Msg("--debug flag, forcing debug log level") } else { if viper.IsSet(config.KeyLogLevel) { level := viper.GetString(config.KeyLogLevel) switch level { case "panic": zerolog.SetGlobalLevel(zerolog.PanicLevel) break case "fatal": zerolog.SetGlobalLevel(zerolog.FatalLevel) break case "error": zerolog.SetGlobalLevel(zerolog.ErrorLevel) break case "warn": zerolog.SetGlobalLevel(zerolog.WarnLevel) break case "info": zerolog.SetGlobalLevel(zerolog.InfoLevel) break case "debug": zerolog.SetGlobalLevel(zerolog.DebugLevel) break case "disabled": zerolog.SetGlobalLevel(zerolog.Disabled) break default: return errors.Errorf("Unknown log level (%s)", level) } log.Debug().Str("log-level", level).Msg("Logging level") } } return nil }, PreRunE: func(cmd *cobra.Command, args []string) error { if viper.GetBool(config.KeyShowVersion) { fmt.Printf("%s v%s - commit: %s, date: %s, tag: %s\n", release.NAME, release.VERSION, release.COMMIT, release.DATE, release.TAG) os.Exit(0) } if viper.GetBool(config.KeyShowConfig) { showConfig() os.Exit(0) } log.Info(). Int("pid", os.Getpid()). Str("name", release.NAME). Str("ver", release.VERSION).Msg("Starting") if err := config.Validate(); err != nil { return err } return nil }, Run: func(cmd *cobra.Command, args []string) { defer log.Info(). Int("pid", os.Getpid()). Str("name", release.NAME). Str("ver", release.VERSION).Msg("Stopping") a, err := agent.New() if err != nil { log.Fatal().Err(err).Msg("Initializing") return } a.Start() defer a.Stop() if err := a.Wait(); err != nil { log.Fatal().Err(err).Msg("Startup") } return }, }
RootCmd represents the base command when called without any subcommands
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.