Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.

Commit e471a00

Browse files
authored
Merge pull request #99 from github/add-more-cmds-to-cli
Add more cmds to cli
2 parents d0d3dd7 + cdef137 commit e471a00

File tree

3 files changed

+101
-14
lines changed

3 files changed

+101
-14
lines changed

README.md

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,33 @@ Usage:
2929
vulcanizer [command]
3030
3131
Available Commands:
32-
aliases Interact with aliases of the cluster.
33-
allocation Set shard allocation on the cluster.
34-
analyze Analyze text given an analyzer or a field and index.
35-
drain Drain a server or see what servers are draining.
36-
fill Fill servers with data, removing shard allocation exclusion rules.
37-
health Display the health of the cluster.
38-
help Help about any command
39-
indices Display the indices of the cluster.
40-
nodes Display the nodes of the cluster.
41-
repository Interact with the configured snapshot repositories.
42-
setting Interact with cluster settings.
43-
settings Display all the settings of the cluster.
44-
shards Get shard data by cluster node(s).
45-
snapshot Interact with a specific snapshot.
32+
aliases Interact with aliases of the cluster.
33+
allocation Set shard allocation on the cluster.
34+
analyze Analyze text given an analyzer or a field and index.
35+
drain Drain a server or see what servers are draining.
36+
fill Fill servers with data, removing shard allocation exclusion rules.
37+
health Display the health of the cluster.
38+
heap Display the node heap stats.
39+
help Help about any command
40+
hotthreads Display the current hot threads by node in the cluster.
41+
indices Display the indices of the cluster.
42+
mappings Display the mappings of the specified index.
43+
nodeallocations Display the nodes of the cluster and their disk usage/allocation.
44+
nodes Display the nodes of the cluster.
45+
repository Interact with the configured snapshot repositories.
46+
setting Interact with cluster settings.
47+
settings Display all the settings of the cluster.
48+
shards Get shard data by cluster node(s).
49+
snapshot Interact with a specific snapshot.
4650
4751
Flags:
52+
--cacert string Path to the certificate to check the cluster certificates against
53+
--cert string Path to the certificate to use for client certificate authentication
4854
-c, --cluster string Cluster to connect to defined in config file
4955
-f, --configFile string Configuration file to read in (default to "~/.vulcanizer.yaml")
5056
-h, --help help for vulcanizer
5157
--host string Host to connect to (default "localhost")
58+
--key string Path to the key to use for client certificate authentication
5259
--password string Password to use during authentication
5360
--path string Path to prepend to queries, in case Elasticsearch is behind a reverse proxy
5461
-p, --port int Port to connect to (default 9200)

pkg/cli/hotthreads.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package cli
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/spf13/cobra"
8+
)
9+
10+
var nodesToGetHotThreads []string
11+
12+
func init() {
13+
cmdHotThreads.Flags().StringArrayVarP(&nodesToGetHotThreads, "nodes", "n", []string{}, "Elasticsearch nodes to get hot threads for. (optional, omitted will include all nodes)")
14+
rootCmd.AddCommand(cmdHotThreads)
15+
}
16+
17+
var cmdHotThreads = &cobra.Command{
18+
Use: "hotthreads",
19+
Short: "Display the current hot threads by node in the cluster.",
20+
Long: `Show the current hot threads across a set of nodes within the cluster.`,
21+
Run: func(cmd *cobra.Command, args []string) {
22+
23+
v := getClient()
24+
25+
if len(nodesToGetHotThreads) == 0 {
26+
threads, err := v.GetHotThreads()
27+
if err != nil {
28+
fmt.Printf("Error getting hot threads: %s\n", err)
29+
os.Exit(1)
30+
}
31+
fmt.Println(threads)
32+
return
33+
}
34+
35+
threads, err := v.GetNodesHotThreads(nodesToGetHotThreads)
36+
if err != nil {
37+
fmt.Printf("Error getting mappings: %s\n", err)
38+
os.Exit(1)
39+
}
40+
fmt.Println(threads)
41+
},
42+
}

pkg/cli/mappings.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package cli
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/spf13/cobra"
8+
)
9+
10+
var indexToGetMappings string
11+
12+
func init() {
13+
cmdIndexMappings.Flags().StringVarP(&indexToGetMappings, "index", "i", "", "Elasticsearch index to retrieve mappings from (required)")
14+
err := cmdIndexMappings.MarkFlagRequired("index")
15+
if err != nil {
16+
fmt.Printf("Error binding name configuration flag: %s \n", err)
17+
os.Exit(1)
18+
}
19+
rootCmd.AddCommand(cmdIndexMappings)
20+
}
21+
22+
var cmdIndexMappings = &cobra.Command{
23+
Use: "mappings",
24+
Short: "Display the mappings of the specified index.",
25+
Long: `Show the mappings of the specified index within the cluster.`,
26+
Run: func(cmd *cobra.Command, args []string) {
27+
28+
v := getClient()
29+
30+
mappings, err := v.GetPrettyIndexMappings(indexToGetMappings)
31+
32+
if err != nil {
33+
fmt.Printf("Error getting mappings: %s\n", err)
34+
os.Exit(1)
35+
}
36+
fmt.Println(mappings)
37+
},
38+
}

0 commit comments

Comments
 (0)