Skip to content

Commit 22ef2e9

Browse files
0.0.5
1 parent 127e88b commit 22ef2e9

File tree

27 files changed

+1194
-893
lines changed

27 files changed

+1194
-893
lines changed

README.md

Lines changed: 117 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,27 @@ $ escli index settings my-index-000001 number_of_replicas 2
1818
## Release Note
1919
Release Note is [Here](RELEASENOTE.md)
2020

21+
>**WARNING**
22+
>If you used escli 0.0.4, you have to change your config file. configuration field `elasticsearch_url` is changed `url`.
23+
24+
[AS-IS]
25+
```bash
26+
- profile: localhost
27+
elasticsearch_url: http://localhost:9200
28+
aws_region: ap-northeast-2
29+
```
30+
31+
[TO-BE]
32+
```bash
33+
- profile: localhost
34+
url: http://localhost:9200
35+
aws_region: ap-northeast-2
36+
```
37+
2138
## Installation
2239
### Required
2340
- [elasticsearch](https://elastic.co) version 6.0 or higher
41+
- [opensearch](https://opensearch.org) version 1.0 or higher
2442

2543
### Install escli binary
2644

@@ -41,20 +59,54 @@ $ sudo install escli /usr/bin
4159
configuration of escli is stored at `~/.escli/config.yaml` file.
4260
for the first time, there is no configuration so you have to initialize configuration with `escli profiles add`
4361
```bash
44-
$ escli profiles add
45-
? Your Profile Name : log-es
46-
? Your ElasticSearch URL : http://elasticsearch.domain.com:9200
47-
? Your AWS Default Region (If you don't use AWS, type blank) : ap-northeast-2
48-
- profile: log-es
49-
elasticsearch_url: http://elasticsearch.domain.com:9200
50-
aws_region: ap-northeast-2
51-
52-
? Are you sure to add profile to configuration file? y
53-
Adding profile to configuration file is successfully in /Users/benx/.escli/config.yaml
62+
? Your Profile Name : localhost
63+
? Your ElasticSearch or OpenSearch URL : https://localhost:9200
64+
? Select your product (elasticsearch or opensearch) : elasticsearch
65+
? Your AWS Default Region (If you don't use AWS, type blank) :
66+
? Your HTTP Username (If you don't use http basic authentication, type blank) : elastic
67+
? Your HTTP Password (If you don't use http basic authentication, type blank) : ********************
68+
? Your certificateFingerPrint (If you don't use certificate finger print, type blank) : 67c2d588a7a6a50e773d0cc91f83cab7a6c11a19e199f3f075b9b6d873a5992a
69+
- profile: localhost
70+
url: https://localhost:9200
71+
product: elasticsearch
72+
http_username: elastic
73+
http_password: qZzEp0Hc112zYx=Z+xQb
74+
certificate_finger_print: 67c2d588a7a6a50e773d0cc91f83cab7a6c11a19e199f3f075b9b6d873a5992a
75+
76+
? Are you sure to add profile to configuration file? yes
77+
Adding profile to configuration file is successfully in /Users/alden/.escli/config.yaml
5478
```
5579

5680
## How to use
5781

82+
### configuration
83+
| field | description |
84+
| ------|-----------------------------------------------------------------------------------------|
85+
| profile | name of profile |
86+
| url | url of target system |
87+
| product | product of target system. elasticsearch or opensearch (default : elasticsearch) |
88+
| aws_region | aws region that you use |
89+
| http_username | http username of target system. It is needed if you use basic http authentication. |
90+
| http_password | http password of target system. |
91+
| certificate_fingerprint | certificate fingerprint of target system |
92+
#### configuration example
93+
```bash
94+
- profile: dev-access-log
95+
url: https://dev-access-log.ap-northeast-2.es.amazonaws.com
96+
product: opensearch
97+
- profile: prod-access-log
98+
url: https://prod-access-log.ap-northeast-2.es.amazonaws.com
99+
product: opensearch
100+
http_username: elastic
101+
http_password: abcdefg
102+
- profile: localhost
103+
url: https://localhost:9200
104+
product: elasticsearch
105+
http_username: elastic
106+
http_password: qZzEp0Hc112zYx=Z+xQb
107+
certificate_finger_print: 67c2d588a7a6a50e773d0cc91f83cab7a6c11a19e199f3f075b9b6d873a5992a
108+
```
109+
58110
### common options
59111
* `--profile` : you can specify profile from configuration file. if you don't specify `--profile` option, escli use first profile of configuration file.
60112
* `--config` : you can specify configuration file. if you don't specify `--config` option, escli use `~/.escli/config.yaml` configuration file.
@@ -73,26 +125,32 @@ you can add one more elasticsearch clusters to your configuration file by `profi
73125

74126
```bash
75127
$ escli profiles add
76-
? Your Profile Name : service-es
77-
? Your ElasticSearch URL : http://search.domain.com:9200
78-
? Your AWS Default Region (If you don't use AWS, type blank) :
79-
- profile: service-es
80-
elasticsearch_url: http://search.domain.com:9200
81-
aws_region: ""
82-
83-
? Are you sure to add profile to configuration file? y
84-
Adding profile to configuration file is successfully in /Users/benx/.escli/config.yaml
128+
? Your Profile Name : localhost
129+
? Your ElasticSearch or OpenSearch URL : https://localhost:9200
130+
? Select your product (elasticsearch or opensearch) : elasticsearch
131+
? Your AWS Default Region (If you don't use AWS, type blank) :
132+
? Your HTTP Username (If you don't use http basic authentication, type blank) : elastic
133+
? Your HTTP Password (If you don't use http basic authentication, type blank) : ********************
134+
? Your certificateFingerPrint (If you don't use certificate finger print, type blank) : 67c2d588a7a6a50e773d0cc91f83cab7a6c11a19e199f3f075b9b6d873a5992a
135+
- profile: localhost
136+
url: https://localhost:9200
137+
product: elasticsearch
138+
http_username: elastic
139+
http_password: qZzEp0Hc112zYx=Z+xQb
140+
certificate_finger_print: 67c2d588a7a6a50e773d0cc91f83cab7a6c11a19e199f3f075b9b6d873a5992a
141+
142+
? Are you sure to add profile to configuration file? yes
143+
Adding profile to configuration file is successfully in /Users/alden/.escli/config.yaml
85144
```
86145

87146
```bash
88147
$ escli profiles list
89-
Profile : log-es
90-
ElasticSearch URL : http://elasticsearch.domain.com:9200
91-
AWS Region : ap-northeast-2
92-
93-
Profile : service-es
94-
ElasticSearch URL : http://search.domain.com:9200
95-
AWS Region :
148+
Profile : localhost
149+
URL : https://localhost:9200
150+
Product : elasticsearch
151+
HTTP Username : elastic
152+
HTTP Password : ************
153+
Certificate Finger Print : 67c2d588a7a6a50e773d0cc91f83cab7a6c11a19e199f3f075b9b6d873a5992a
96154
```
97155

98156
```bash
@@ -146,6 +204,8 @@ application-log-2021.01.06 green open 100 1
146204

147205
### `snapshot` command
148206

207+
`snapshot` command doesn't support OpenSearch.
208+
149209
#### command list
150210
| command | description |
151211
| ----------- | --------------------------------------------------------- |
@@ -190,9 +250,13 @@ elasticsearch-snapshot-standard/indices/z8bqmUmAQxy8tuwSsmFEKg/0/__-urzTmmuR8K6s
190250
### `index` command
191251

192252
#### command list
193-
| command | description |
194-
| ------- | ---------------- |
253+
| command | description |
254+
|----------------| ---------------- |
195255
| index settings | get or set index settings |
256+
| index delete | delete index |
257+
| index create | create index |
258+
| index stats | show statistics of index |
259+
196260

197261
#### examples
198262

@@ -236,6 +300,18 @@ $ escli index settings send-mail-result-prod-2021-01-12 number_of_replicas 2
236300
}
237301
```
238302

303+
```bash
304+
$ escli index stats access_log-2023.02.13 1 --profile=localhost
305+
time index total shards successful shards failed shards indexing rate indexing latency (ms) query rate query latency (ms) fetch rate fetch latency (ms)
306+
16:08:13 access_log-2023.02.13 12 12 0 3182 0.13 0 0.00 0 0.00
307+
16:08:14 access_log-2023.02.13 12 12 0 2348 0.09 0 0.00 0 0.00
308+
16:08:15 access_log-2023.02.13 12 12 0 2466 0.12 0 0.00 0 0.00
309+
16:08:16 access_log-2023.02.13 12 12 0 0 0.00 0 0.00 0 0.00
310+
16:08:17 access_log-2023.02.13 12 12 0 6046 0.14 0 0.00 0 0.00
311+
16:08:18 access_log-2023.02.13 12 12 0 5056 0.17 0 0.00 0 0.00
312+
16:08:19 access_log-2023.02.13 12 12 0 1286 0.10 0 0.00 0 0.00
313+
```
314+
239315
### `cluster` command
240316

241317
#### command list
@@ -273,6 +349,19 @@ check number of master nodes...................[3]
273349
check maximum disk used percent of nodes.......[36]
274350
```
275351
352+
### `stats` command
353+
354+
#### examples
355+
356+
```bash
357+
$ escli stats 1 --profile=localhost
358+
time total shards successful shards failed shards indexing rate indexing latency (ms) query rate query latency (ms) fetch rate fetch latency (ms)
359+
16:10:32 204 204 0 10591 0.47 0 0.00 0 0.00
360+
16:10:33 204 204 0 1099 8.16 0 0.00 0 0.00
361+
16:10:34 204 204 0 3267 0.13 0 0.00 0 0.00
362+
16:10:35 204 204 0 1869 0.13 0 0.00 0 0.00
363+
```
364+
276365
## Autocompletion
277366
* zsh
278367
```bash

RELEASENOTE.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Release Note
22

3+
## 0.0.5 (2023/02/13)
4+
- `escli` supports OpenSearch.
5+
- `index stats` command shows statistics of index.
6+
- `stats` command shows statistics of cluster.
7+
- `index create` command create index.
8+
39
## 0.0.4 (2021/03/30)
410
- autocomplete is included.
511
- `profiles list` command shows all profiles of escli.

cmd/cmd/builder/builder.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ func (b builder) WithDescription(description string) Builder {
5353
return b
5454
}
5555

56-
func (b builder) WithUsageTemplate(s string) {
57-
b.cmd.SetUsageTemplate("abc")
58-
}
59-
6056
func (b builder) ExactArgs(argCount int, action func(context.Context, io.Writer, []string) error) *cobra.Command {
6157
b.cmd.Args = cobra.ExactArgs(argCount)
6258
b.cmd.RunE = func(cmd *cobra.Command, args []string) error {

cmd/cmd/builder/example.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ var ExampleList = []Example{
4444
Description: " escli snapshot archive application-log snapshot-2020.01.01",
4545
DefinedOn: []string{"snapshot archive [repositoryID] [snapshotID]"},
4646
},
47+
{
48+
Description: " escli index stats logs-2020.01.01 1",
49+
DefinedOn: []string{"index stats [index name] [interval]"},
50+
},
4751
}
4852

4953
func SetCommandExample(cmd *cobra.Command) {

cmd/cmd/cat.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func NewCatCommand() *cobra.Command {
4242

4343
builder.SetCommandFlags(catIndicesCommand)
4444
builder.SetCommandFlags(catShardsCommand)
45+
builder.SetCommandFlags(catNodesCommand)
4546

4647
return cmd
4748
}

cmd/cmd/cmd.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func NewRootCommand(out, stderr io.Writer) *cobra.Command {
3737
Short: "manage elasticsearch cluster",
3838
Long: "manage elasticsearch cluster",
3939
SilenceErrors: true,
40-
SilenceUsage: true,
40+
SilenceUsage: false,
4141
}
4242

4343
rootCmd.AddCommand(NewSnapshotCommand())
@@ -50,6 +50,7 @@ func NewRootCommand(out, stderr io.Writer) *cobra.Command {
5050
rootCmd.AddCommand(NewUpdateCommand())
5151
rootCmd.AddCommand(NewCompletionCommand())
5252
rootCmd.AddCommand(NewProfilesCommand())
53+
rootCmd.AddCommand(NewStatsCommand())
5354

5455
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file")
5556
rootCmd.PersistentFlags().StringVar(&profile, "profile", "", "profile")

cmd/cmd/index.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,18 @@ func NewIndexCommand() *cobra.Command {
3232

3333
indexSettingsCommand := index.NewIndexSettingsCommand()
3434
indexDeleteCommand := index.NewIndexDeleteCommand()
35+
indexStatsCommand := index.NewIndexStatsCommand()
36+
indexCreateCommand := index.NewIndexCreateCommand()
3537

3638
cmd.AddCommand(indexSettingsCommand)
3739
cmd.AddCommand(indexDeleteCommand)
40+
cmd.AddCommand(indexStatsCommand)
41+
cmd.AddCommand(indexCreateCommand)
3842

3943
builder.SetCommandFlags(indexSettingsCommand)
4044
builder.SetCommandFlags(indexDeleteCommand)
45+
builder.SetCommandFlags(indexCreateCommand)
46+
builder.SetCommandExample(indexStatsCommand)
4147

4248
return cmd
4349
}

cmd/cmd/index/create.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
copyright 2020 the Escli authors
3+
4+
licensed under the apache license, version 2.0 (the "license");
5+
you may not use this file except in compliance with the license.
6+
you may obtain a copy of the license at
7+
8+
http://www.apache.org/licenses/license-2.0
9+
10+
unless required by applicable law or agreed to in writing, software
11+
distributed under the license is distributed on an "as is" basis,
12+
without warranties or conditions of any kind, either express or implied.
13+
see the license for the specific language governing permissions and
14+
limitations under the license.
15+
*/
16+
17+
package index
18+
19+
import (
20+
"context"
21+
"io"
22+
23+
"github.com/spf13/cobra"
24+
25+
"github.com/DevopsArtFactory/escli/cmd/cmd/builder"
26+
"github.com/DevopsArtFactory/escli/internal/executor"
27+
)
28+
29+
func NewIndexCreateCommand() *cobra.Command {
30+
return builder.NewCmd("create").
31+
WithDescription("create index").
32+
ExactArgs(1, funcIndexCreate)
33+
}
34+
35+
func funcIndexCreate(ctx context.Context, out io.Writer, args []string) error {
36+
return executor.RunExecutor(ctx, func(executor executor.Executor) error {
37+
return executor.Runner.CreateIndex(out, args)
38+
})
39+
}

cmd/cmd/index/stats.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
copyright 2020 the Escli authors
3+
4+
licensed under the apache license, version 2.0 (the "license");
5+
you may not use this file except in compliance with the license.
6+
you may obtain a copy of the license at
7+
8+
http://www.apache.org/licenses/license-2.0
9+
10+
unless required by applicable law or agreed to in writing, software
11+
distributed under the license is distributed on an "as is" basis,
12+
without warranties or conditions of any kind, either express or implied.
13+
see the license for the specific language governing permissions and
14+
limitations under the license.
15+
*/
16+
17+
package index
18+
19+
import (
20+
"context"
21+
"io"
22+
23+
"github.com/spf13/cobra"
24+
25+
"github.com/DevopsArtFactory/escli/cmd/cmd/builder"
26+
"github.com/DevopsArtFactory/escli/internal/executor"
27+
)
28+
29+
func NewIndexStatsCommand() *cobra.Command {
30+
return builder.NewCmd("stats [index name] [interval]").
31+
WithDescription("show stats of index").
32+
ExactArgs(2, funcIndexStats)
33+
}
34+
35+
func funcIndexStats(ctx context.Context, out io.Writer, args []string) error {
36+
return executor.RunExecutor(ctx, func(executor executor.Executor) error {
37+
return executor.Runner.StatsIndex(out, args)
38+
})
39+
}

0 commit comments

Comments
 (0)