mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 13:24:19 +02:00
Compare commits
1 Commits
55a1005857
...
fix/crashe
| Author | SHA1 | Date | |
|---|---|---|---|
| 54610cdbb4 |
@@ -34,7 +34,6 @@ const (
|
|||||||
Cilm
|
Cilm
|
||||||
Cnode
|
Cnode
|
||||||
Cclustersettings
|
Cclustersettings
|
||||||
Cindextemplate
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func complete(conf *cfg.Config, cmd *cli.Command, what int) {
|
func complete(conf *cfg.Config, cmd *cli.Command, what int) {
|
||||||
@@ -66,8 +65,6 @@ func complete(conf *cfg.Config, cmd *cli.Command, what int) {
|
|||||||
list, err = es.NodeNames(conf)
|
list, err = es.NodeNames(conf)
|
||||||
case Cclustersettings:
|
case Cclustersettings:
|
||||||
list, err = es.ClusterSettingsNames(conf)
|
list, err = es.ClusterSettingsNames(conf)
|
||||||
case Cindextemplate:
|
|
||||||
list, err = es.IndexTemplateNames(conf)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -49,23 +49,8 @@ func IndexTemplateList(conf *cfg.Config) *cli.Command {
|
|||||||
Aliases: []string{"ls"},
|
Aliases: []string{"ls"},
|
||||||
Usage: "list index templates",
|
Usage: "list index templates",
|
||||||
|
|
||||||
Flags: []cli.Flag{
|
|
||||||
&cli.StringSliceFlag{
|
|
||||||
Name: "filter-index-pattern",
|
|
||||||
Usage: "show only index templates which use patterns, which match the filter",
|
|
||||||
Destination: &conf.Filter,
|
|
||||||
Aliases: []string{"F"},
|
|
||||||
},
|
|
||||||
&cli.BoolFlag{
|
|
||||||
Name: "hidden",
|
|
||||||
Usage: "show hidden index templates as well",
|
|
||||||
Destination: &conf.Hidden,
|
|
||||||
Aliases: []string{"H"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||||
return es.IndexTemplateList(conf, cmd.Args().Get(0))
|
return es.IndexTemplateList(conf)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,7 +71,7 @@ func IndexTemplateShow(conf *cfg.Config) *cli.Command {
|
|||||||
},
|
},
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cindextemplate)
|
complete(conf, cmd, Cindex)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -230,7 +215,7 @@ func IndexTemplateDelete(conf *cfg.Config) *cli.Command {
|
|||||||
},
|
},
|
||||||
|
|
||||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||||
complete(conf, cmd, Cindextemplate)
|
complete(conf, cmd, Cindex)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,23 +33,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// used for completion
|
// used for completion
|
||||||
func IndexTemplateNames(conf *cfg.Config) ([]string, error) {
|
func IndexTemplateList(conf *cfg.Config) error {
|
||||||
res, err := conf.DefaultCluster.ES().Indices.GetIndexTemplate().
|
|
||||||
Do(context.Background())
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to get index templates: %w", esErrorString(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
names := make([]string, len(res.IndexTemplates))
|
|
||||||
|
|
||||||
for idx, tpl := range res.IndexTemplates {
|
|
||||||
names[idx] = tpl.Name
|
|
||||||
}
|
|
||||||
|
|
||||||
return names, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func IndexTemplateList(conf *cfg.Config, filter string) error {
|
|
||||||
res, err := conf.DefaultCluster.ES().Indices.GetIndexTemplate().
|
res, err := conf.DefaultCluster.ES().Indices.GetIndexTemplate().
|
||||||
Do(context.Background())
|
Do(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -58,42 +42,20 @@ func IndexTemplateList(conf *cfg.Config, filter string) error {
|
|||||||
|
|
||||||
slog.Debug("res", "index templates", res)
|
slog.Debug("res", "index templates", res)
|
||||||
|
|
||||||
table := printer.NewTable(conf, 5, 0)
|
table := printer.NewTable(conf, 5, len(res.IndexTemplates))
|
||||||
table.Addheaders("name", "description", "index patterns", "priority")
|
table.Addheaders("name", "description", "priority")
|
||||||
|
|
||||||
for _, tpl := range res.IndexTemplates {
|
for idx, tpl := range res.IndexTemplates {
|
||||||
if !conf.Hidden && strings.HasPrefix(tpl.Name, ".") {
|
desc, err := json.Marshal(tpl.IndexTemplate.Meta_["description"])
|
||||||
continue
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to unmarshal meta json data: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if filter != "" && !strings.Contains(tpl.Name, filter) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(conf.Filter) > 0 {
|
|
||||||
skip := true
|
|
||||||
|
|
||||||
for _, filter := range conf.Filter {
|
|
||||||
for _, pattern := range tpl.IndexTemplate.IndexPatterns {
|
|
||||||
if strings.Contains(pattern, filter) {
|
|
||||||
skip = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if skip {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
desc := strings.TrimPrefix(strings.TrimSuffix(string(tpl.IndexTemplate.Meta_["description"]), `"`), `"`)
|
|
||||||
|
|
||||||
var prio int64
|
var prio int64
|
||||||
if tpl.IndexTemplate.Priority != nil {
|
if tpl.IndexTemplate.Priority != nil {
|
||||||
prio = *tpl.IndexTemplate.Priority
|
prio = *tpl.IndexTemplate.Priority
|
||||||
}
|
}
|
||||||
|
table.Entries[idx] = []any{tpl.Name, desc, prio}
|
||||||
table.AddRow(tpl.Name, desc, tpl.IndexTemplate.IndexPatterns, prio)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
table.Sort()
|
table.Sort()
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright © 2026 Thomas von Dein
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package printer
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"runtime/metrics"
|
|
||||||
"strconv"
|
|
||||||
)
|
|
||||||
|
|
||||||
func printGoRoutineMetrics() {
|
|
||||||
fmt.Println("\nGoroutine metrics:")
|
|
||||||
printMetric("/sched/goroutines-created:goroutines", "Created")
|
|
||||||
printMetric("/sched/goroutines:goroutines", "Live")
|
|
||||||
printMetric("/sched/goroutines/not-in-go:goroutines", "Syscall/CGO")
|
|
||||||
printMetric("/sched/goroutines/runnable:goroutines", "Runnable")
|
|
||||||
printMetric("/sched/goroutines/running:goroutines", "Running")
|
|
||||||
printMetric("/sched/goroutines/waiting:goroutines", "Waiting")
|
|
||||||
|
|
||||||
fmt.Println("Thread metrics:")
|
|
||||||
printMetric("/sched/gomaxprocs:threads", "Max")
|
|
||||||
printMetric("/sched/threads/total:threads", "Live")
|
|
||||||
}
|
|
||||||
|
|
||||||
func printMetric(name string, descr string) {
|
|
||||||
sample := []metrics.Sample{{Name: name}}
|
|
||||||
metrics.Read(sample)
|
|
||||||
|
|
||||||
var val string
|
|
||||||
|
|
||||||
switch sample[0].Value.Kind() {
|
|
||||||
case metrics.KindFloat64, metrics.KindFloat64Histogram:
|
|
||||||
val = fmt.Sprintf("%.2f", sample[0].Value.Float64())
|
|
||||||
case metrics.KindUint64:
|
|
||||||
val = strconv.FormatUint(sample[0].Value.Uint64(), 10)
|
|
||||||
case metrics.KindBad:
|
|
||||||
val = "n/a"
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf(" %s: %v\n", descr, val)
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user