cmd

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2020 License: BSD-3-Clause Imports: 15 Imported by: 1

Documentation

Overview

Package cmd defines the CLI for the agent

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: initLogging,
	Run: func(cmd *cobra.Command, args []string) {

		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)
			return
		}

		if !viper.IsSet(config.KeyCollectors) {
			if !viper.GetBool(config.KeyMultiAgent) {
				viper.Set(config.KeyCollectors, defaults.Collectors)
			}
		}

		if viper.GetString(config.KeyShowConfig) != "" {
			if err := config.ShowConfig(os.Stdout); err != nil {
				log.Fatal().Err(err).Msg("show-config")
			}
			return
		}

		log.Info().
			Int("pid", os.Getpid()).
			Str("name", release.NAME).
			Str("ver", release.VERSION).Msg("Starting")

		a, err := agent.New()
		if err != nil {
			log.Fatal().Err(err).Msg("initializing")
		}

		if err := config.StatConfig(); err != nil {
			log.Fatal().Err(err).Msg("initializing internal stats")
		}

		if err := a.Start(); err != nil {
			log.Fatal().Err(err).Msg("starting agent")
		}
	},
}

RootCmd represents the base command when called without any subcommands

Functions

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL