Skip to content

Commit e744248

Browse files
committed
add traffic shaping info
1 parent 7cfd6d0 commit e744248

2 files changed

Lines changed: 462 additions & 24 deletions

File tree

internal/eosgrpc/client.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,24 @@ type NamespaceStats struct {
157157
CacheContainersHits uint64
158158
}
159159

160+
type IOShapingMode int
161+
162+
const (
163+
IOShapingApps IOShapingMode = iota
164+
IOShapingUsers
165+
IOShapingGroups
166+
)
167+
168+
type IOShapingRecord struct {
169+
ID string
170+
Type string
171+
WindowSec int
172+
ReadBps float64
173+
WriteBps float64
174+
ReadIOPS float64
175+
WriteIOPS float64
176+
}
177+
160178
func New(_ context.Context, cfg Config) (*Client, error) {
161179
timeout := cfg.Timeout
162180
if timeout <= 0 {
@@ -583,6 +601,47 @@ func (c *Client) nodeStatsViaCLI() (NodeStats, error) {
583601
return stats, nil
584602
}
585603

604+
func (c *Client) IOShaping(ctx context.Context, mode IOShapingMode) ([]IOShapingRecord, error) {
605+
flag := "--apps"
606+
switch mode {
607+
case IOShapingUsers:
608+
flag = "--users"
609+
case IOShapingGroups:
610+
flag = "--groups"
611+
}
612+
output, err := c.runCommand("eos", "io", "shaping", "ls", flag, "--json", "--window", "5")
613+
if err != nil {
614+
return nil, fmt.Errorf("io shaping ls: %w: %s", err, strings.TrimSpace(string(output)))
615+
}
616+
617+
var raw []struct {
618+
ID string `json:"id"`
619+
Type string `json:"type"`
620+
WindowSec int `json:"window_sec"`
621+
ReadBps float64 `json:"read_rate_bps"`
622+
WriteBps float64 `json:"write_rate_bps"`
623+
ReadIOPS float64 `json:"read_iops"`
624+
WriteIOPS float64 `json:"write_iops"`
625+
}
626+
if err := json.Unmarshal(output, &raw); err != nil {
627+
return nil, fmt.Errorf("parse io shaping: %w", err)
628+
}
629+
630+
records := make([]IOShapingRecord, len(raw))
631+
for i, r := range raw {
632+
records[i] = IOShapingRecord{
633+
ID: r.ID,
634+
Type: r.Type,
635+
WindowSec: r.WindowSec,
636+
ReadBps: r.ReadBps,
637+
WriteBps: r.WriteBps,
638+
ReadIOPS: r.ReadIOPS,
639+
WriteIOPS: r.WriteIOPS,
640+
}
641+
}
642+
return records, nil
643+
}
644+
586645
func (c *Client) runCommand(args ...string) ([]byte, error) {
587646
if c.sshTarget == "" {
588647
return exec.Command(args[0], args[1:]...).CombinedOutput()

0 commit comments

Comments
 (0)