mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 15:04:19 +02:00
58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
/*
|
|
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 es
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log/slog"
|
|
|
|
"codeberg.org/scip/esctl/pkg/cfg"
|
|
)
|
|
|
|
func NodeList(conf *cfg.Config) error {
|
|
// get nodes
|
|
nodes, err := conf.DefaultCluster.ES.Cat.Nodes().Do(context.Background())
|
|
if err != nil {
|
|
return fmt.Errorf("failed to get nodes: %s", err)
|
|
}
|
|
|
|
slog.Debug("ES result", "nodes", nodes)
|
|
|
|
table := NewTable(7, len(nodes))
|
|
table.Addheaders("name", "ip", "load1m", "load5m", "load15m", "ram %", "heap %")
|
|
|
|
for idx, node := range nodes {
|
|
table.entries[idx] = []string{
|
|
*node.Name,
|
|
*node.Ip,
|
|
*node.Load1M,
|
|
*node.Load5M,
|
|
*node.Load15M,
|
|
node.RamPercent.(string),
|
|
node.HeapPercent.(string),
|
|
}
|
|
}
|
|
|
|
table.Sort()
|
|
if err := table.PrintMarkdown(); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|