/
cat.go
234 lines (211 loc) · 6.97 KB
/
cat.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
package main
import (
"strings"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// catCmd represents the cat command
var catCmd = &cobra.Command{
Use: "cat",
Short: "Query the cat apis",
Long: `JSON is great… for computers. Even if it’s pretty-printed,
trying to find relationships in the data is tedious. Human eyes,
especially when looking at an ssh terminal, need compact and aligned text.
The cat API aims to meet this need.`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
viper.Set("pretty", false)
client = configESClient()
},
}
var catAliases = &cobra.Command{
Use: "aliases",
Aliases: []string{"alias"},
Short: "list configured aliases",
Long: `Aliases shows information about currently configured aliases to indices including filter and routing infos.`,
Run: func(cmd *cobra.Command, args []string) {
response := client.Cat(cmd.Name())
printResponse(response)
},
}
var catAllocation = &cobra.Command{
Use: "allocation",
Short: "display shard allocation",
Long: `Allocation provides a snapshot of how many shards are allocated to each data node and how much disk space they are using.`,
Run: func(cmd *cobra.Command, args []string) {
response := client.Cat(cmd.Name())
printResponse(response)
},
}
var catCount = &cobra.Command{
Use: "count [index]",
Short: "get document counts",
Long: `Count provides quick access to the document count of the entire cluster, or individual indices`,
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
var response string
if len(args) > 0 {
response = client.CatCountIndex(args[0])
} else {
response = client.Cat(cmd.Name())
}
printResponse(response)
},
}
var catFielddata = &cobra.Command{
Use: "fielddata",
Short: "info on fieldata heap usage",
Long: `Fielddata shows how much heap memory is currently being used by fielddata on every data node in the cluster.`,
Run: func(cmd *cobra.Command, args []string) {
response := client.Cat(cmd.Name())
printResponse(response)
},
}
var catHealth = &cobra.Command{
Use: "health",
Short: "info on cluster health",
Long: `Health is a terse, one-line representation of the same information from ` + "`cluster health`",
Run: func(cmd *cobra.Command, args []string) {
response := client.Cat(cmd.Name())
printResponse(response)
},
}
var catIndices = &cobra.Command{
Use: "indices",
Aliases: []string{"index", "indexes"},
Short: "summary of all indices",
Long: `The indices command provides a cross-section of each index. This information spans nodes.`,
Run: func(cmd *cobra.Command, args []string) {
response := client.Cat(cmd.Name())
printResponse(response)
},
}
var catMaster = &cobra.Command{
Use: "master",
Short: "master node summary",
Long: `Displays the master’s node ID, bound IP address, and node name.`,
Run: func(cmd *cobra.Command, args []string) {
response := client.Cat(cmd.Name())
printResponse(response)
},
}
var catNodeattrs = &cobra.Command{
Use: "nodeattrs",
Short: "Shows custom node attributes",
Run: func(cmd *cobra.Command, args []string) {
response := client.Cat(cmd.Name())
printResponse(response)
},
}
var catNodes = &cobra.Command{
Use: "nodes",
Short: "Shows the cluster topology",
Run: func(cmd *cobra.Command, args []string) {
response := client.Cat(cmd.Name())
printResponse(response)
},
}
var catNodeType = &cobra.Command{
Use: "type [node-type]",
Short: "Get info on only a certain type of node",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
matches := client.CatNodeType(args[0])
response := strings.Join(matches, "\n")
printResponse(response)
},
}
var catPendingTasks = &cobra.Command{
Use: "pending_tasks",
Short: "List pending tasks",
Run: func(cmd *cobra.Command, args []string) {
response := client.Cat(cmd.Name())
printResponse(response)
},
}
var catPlugins = &cobra.Command{
Use: "plugins",
Short: "list plugins",
Long: `The plugins command provides a view per node of running plugins. This information spans nodes`,
Run: func(cmd *cobra.Command, args []string) {
response := client.Cat(cmd.Name())
printResponse(response)
},
}
var catRecovery = &cobra.Command{
Use: "recovery",
Short: "compact view of the JSON recovery API",
Long: `The recovery command is a view of index shard recoveries, both on-going and previously completed.
A recovery event occurs anytime an index shard moves to a different node in the cluster.
This can happen during a snapshot recovery, a change in replication level, node failure, or on node startup.
This last type is called a local store recovery and is the normal way for shards to be loaded from disk when a node starts up.`,
Run: func(cmd *cobra.Command, args []string) {
response := client.Cat(cmd.Name())
printResponse(response)
},
}
var catRepositories = &cobra.Command{
Use: "repositories",
Aliases: []string{"repos"},
Short: "Shows the snapshot repositories registered in the cluster",
Run: func(cmd *cobra.Command, args []string) {
response := client.Cat(cmd.Name())
printResponse(response)
},
}
var catThreadPool = &cobra.Command{
Use: "thread_pool",
Short: "thread pool info",
Long: `Shows cluster wide thread pool statistics per node`,
Run: func(cmd *cobra.Command, args []string) {
response := client.Cat(cmd.Name())
printResponse(response)
},
}
var catShards = &cobra.Command{
Use: "shards",
Short: "shard info",
Long: `The shards command is the detailed view of what nodes contain which shards.
It will tell you if it’s a primary or replica, the number of docs, the bytes it takes on disk, and the node where it’s located.`,
Run: func(cmd *cobra.Command, args []string) {
response := client.Cat(cmd.Name())
printResponse(response)
},
}
var catSegments = &cobra.Command{
Use: "segments",
Short: "segment info",
Long: `Provides low level information about the segments in the shards of an index.`,
Run: func(cmd *cobra.Command, args []string) {
response := client.Cat(cmd.Name())
printResponse(response)
},
}
var catSnapshots = &cobra.Command{
Use: "snapshots [repository]",
Short: "List snapshots in a repo",
Long: `Shows all snapshots that belong to a specific repository.
To find a list of available repositories to query, the command ` + "`cat repositories`" + ` can be used`,
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
response := client.CatSnapshots(strings.Join(args, ""))
printResponse(response)
},
}
var catTemplates = &cobra.Command{
Use: "templates",
Short: "Provides information about existing templates",
Run: func(cmd *cobra.Command, args []string) {
response := client.Cat(cmd.Name())
printResponse(response)
},
}
func init() {
rootCmd.AddCommand(catCmd)
catCmd.AddCommand(catAliases, catAllocation,
catCount, catFielddata, catHealth, catIndices,
catMaster, catNodeattrs, catNodes,
catPendingTasks, catPlugins, catRecovery,
catRepositories, catThreadPool, catShards,
catSegments, catSnapshots, catTemplates)
catNodes.AddCommand(catNodeType)
}