Skip to content

Commit

Permalink
Merge pull request #99 from github/add-more-cmds-to-cli
Browse files Browse the repository at this point in the history
Add more cmds to cli
  • Loading branch information
hoenn authored Oct 17, 2022
2 parents d0d3dd7 + cdef137 commit e471a00
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 14 deletions.
35 changes: 21 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
42 changes: 42 additions & 0 deletions pkg/cli/hotthreads.go
Original file line number Diff line number Diff line change
@@ -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)
},
}
38 changes: 38 additions & 0 deletions pkg/cli/mappings.go
Original file line number Diff line number Diff line change
@@ -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)
},
}

0 comments on commit e471a00

Please sign in to comment.