diff --git a/README.md b/README.md index 2e5de85..7f8a1eb 100644 --- a/README.md +++ b/README.md @@ -29,26 +29,33 @@ Usage: vulcanizer [command] Available Commands: - aliases Interact with aliases of the cluster. - allocation Set shard allocation on the cluster. - analyze Analyze text given an analyzer or a field and index. - drain Drain a server or see what servers are draining. - fill Fill servers with data, removing shard allocation exclusion rules. - health Display the health of the cluster. - help Help about any command - indices Display the indices of the cluster. - nodes Display the nodes of the cluster. - repository Interact with the configured snapshot repositories. - setting Interact with cluster settings. - settings Display all the settings of the cluster. - shards Get shard data by cluster node(s). - snapshot Interact with a specific snapshot. + aliases Interact with aliases of the cluster. + allocation Set shard allocation on the cluster. + analyze Analyze text given an analyzer or a field and index. + drain Drain a server or see what servers are draining. + fill Fill servers with data, removing shard allocation exclusion rules. + health Display the health of the cluster. + heap Display the node heap stats. + help Help about any command + hotthreads Display the current hot threads by node in the cluster. + indices Display the indices of the cluster. + mappings Display the mappings of the specified index. + nodeallocations Display the nodes of the cluster and their disk usage/allocation. + nodes Display the nodes of the cluster. + repository Interact with the configured snapshot repositories. + setting Interact with cluster settings. + settings Display all the settings of the cluster. + shards Get shard data by cluster node(s). + snapshot Interact with a specific snapshot. Flags: + --cacert string Path to the certificate to check the cluster certificates against + --cert string Path to the certificate to use for client certificate authentication -c, --cluster string Cluster to connect to defined in config file -f, --configFile string Configuration file to read in (default to "~/.vulcanizer.yaml") -h, --help help for vulcanizer --host string Host to connect to (default "localhost") + --key string Path to the key to use for client certificate authentication --password string Password to use during authentication --path string Path to prepend to queries, in case Elasticsearch is behind a reverse proxy -p, --port int Port to connect to (default 9200) diff --git a/pkg/cli/hotthreads.go b/pkg/cli/hotthreads.go new file mode 100644 index 0000000..bfcba1c --- /dev/null +++ b/pkg/cli/hotthreads.go @@ -0,0 +1,42 @@ +package cli + +import ( + "fmt" + "os" + + "github.com/spf13/cobra" +) + +var nodesToGetHotThreads []string + +func init() { + cmdHotThreads.Flags().StringArrayVarP(&nodesToGetHotThreads, "nodes", "n", []string{}, "Elasticsearch nodes to get hot threads for. (optional, omitted will include all nodes)") + rootCmd.AddCommand(cmdHotThreads) +} + +var cmdHotThreads = &cobra.Command{ + Use: "hotthreads", + Short: "Display the current hot threads by node in the cluster.", + Long: `Show the current hot threads across a set of nodes within the cluster.`, + Run: func(cmd *cobra.Command, args []string) { + + v := getClient() + + if len(nodesToGetHotThreads) == 0 { + threads, err := v.GetHotThreads() + if err != nil { + fmt.Printf("Error getting hot threads: %s\n", err) + os.Exit(1) + } + fmt.Println(threads) + return + } + + threads, err := v.GetNodesHotThreads(nodesToGetHotThreads) + if err != nil { + fmt.Printf("Error getting mappings: %s\n", err) + os.Exit(1) + } + fmt.Println(threads) + }, +} diff --git a/pkg/cli/mappings.go b/pkg/cli/mappings.go new file mode 100644 index 0000000..7008857 --- /dev/null +++ b/pkg/cli/mappings.go @@ -0,0 +1,38 @@ +package cli + +import ( + "fmt" + "os" + + "github.com/spf13/cobra" +) + +var indexToGetMappings string + +func init() { + cmdIndexMappings.Flags().StringVarP(&indexToGetMappings, "index", "i", "", "Elasticsearch index to retrieve mappings from (required)") + err := cmdIndexMappings.MarkFlagRequired("index") + if err != nil { + fmt.Printf("Error binding name configuration flag: %s \n", err) + os.Exit(1) + } + rootCmd.AddCommand(cmdIndexMappings) +} + +var cmdIndexMappings = &cobra.Command{ + Use: "mappings", + Short: "Display the mappings of the specified index.", + Long: `Show the mappings of the specified index within the cluster.`, + Run: func(cmd *cobra.Command, args []string) { + + v := getClient() + + mappings, err := v.GetPrettyIndexMappings(indexToGetMappings) + + if err != nil { + fmt.Printf("Error getting mappings: %s\n", err) + os.Exit(1) + } + fmt.Println(mappings) + }, +}