diff --git a/cmd/osctl/cmd/ls.go b/cmd/osctl/cmd/ls.go index acd56a00f..3f8867328 100644 --- a/cmd/osctl/cmd/ls.go +++ b/cmd/osctl/cmd/ls.go @@ -86,15 +86,15 @@ var lsCmd = &cobra.Command{ if info.Error != "" { fmt.Fprintf(os.Stderr, "error reading file %s: %s\n", info.Name, info.Error) } else { - name := info.RelativeName + display := info.RelativeName if info.Link != "" { - name += " -> " + info.Link + display += " -> " + info.Link } fmt.Fprintf(w, "%s\t%d\t%s\t%s\n", os.FileMode(info.Mode).String(), info.Size, time.Unix(info.Modified, 0).Format("Jan 2 2006"), - name, + display, ) } } diff --git a/cmd/osctl/cmd/ps.go b/cmd/osctl/cmd/ps.go index e34167125..ebdbfcb68 100644 --- a/cmd/osctl/cmd/ps.go +++ b/cmd/osctl/cmd/ps.go @@ -8,6 +8,8 @@ package cmd import ( "fmt" "os" + "sort" + "strings" "text/tabwriter" criconstants "github.com/containerd/cri/pkg/constants" @@ -48,10 +50,20 @@ var psCmd = &cobra.Command{ } func processesRender(reply *proto.ProcessesReply) { + sort.Slice(reply.Processes, + func(i, j int) bool { + return strings.Compare(reply.Processes[i].Id, reply.Processes[j].Id) < 0 + }) + w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0) fmt.Fprintln(w, "NAMESPACE\tID\tIMAGE\tPID\tSTATUS") for _, p := range reply.Processes { - fmt.Fprintf(w, "%s\t%s\t%s\t%d\t%s\n", p.Namespace, p.Id, p.Image, p.Pid, p.Status) + display := p.Id + if p.Id != p.PodId { + // container in a sandbox + display = "└─ " + display + } + fmt.Fprintf(w, "%s\t%s\t%s\t%d\t%s\n", p.Namespace, display, p.Image, p.Pid, p.Status) } helpers.Should(w.Flush()) } diff --git a/cmd/osctl/cmd/stats.go b/cmd/osctl/cmd/stats.go index 04b0be64a..dd19916be 100644 --- a/cmd/osctl/cmd/stats.go +++ b/cmd/osctl/cmd/stats.go @@ -8,6 +8,8 @@ package cmd import ( "fmt" "os" + "sort" + "strings" "text/tabwriter" criconstants "github.com/containerd/cri/pkg/constants" @@ -47,10 +49,20 @@ var statsCmd = &cobra.Command{ } func statsRender(reply *proto.StatsReply) { + sort.Slice(reply.Stats, + func(i, j int) bool { + return strings.Compare(reply.Stats[i].Id, reply.Stats[j].Id) < 0 + }) + w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0) fmt.Fprintln(w, "NAMESPACE\tID\tMEMORY(MB)\tCPU") for _, s := range reply.Stats { - fmt.Fprintf(w, "%s\t%s\t%.2f\t%d\n", s.Namespace, s.Id, float64(s.MemoryUsage)*1e-6, s.CpuUsage) + display := s.Id + if s.Id != s.PodId { + // container in a sandbox + display = "└─ " + display + } + fmt.Fprintf(w, "%s\t%s\t%.2f\t%d\n", s.Namespace, display, float64(s.MemoryUsage)*1e-6, s.CpuUsage) } helpers.Should(w.Flush()) } diff --git a/internal/app/osd/internal/reg/reg.go b/internal/app/osd/internal/reg/reg.go index 055219bbd..7acbb3a45 100644 --- a/internal/app/osd/internal/reg/reg.go +++ b/internal/app/osd/internal/reg/reg.go @@ -95,11 +95,13 @@ func (r *Registrator) Processes(ctx context.Context, in *proto.ProcessesRequest) processes := []*proto.Process{} - for _, containers := range pods { - for _, container := range containers.Containers { + for _, pod := range pods { + for _, container := range pod.Containers { process := &proto.Process{ Namespace: in.Namespace, Id: container.Display, + PodId: pod.Name, + Name: container.Name, Image: container.Image, Pid: container.Pid, Status: strings.ToUpper(string(container.Status.Status)), @@ -134,8 +136,8 @@ func (r *Registrator) Stats(ctx context.Context, in *proto.StatsRequest) (reply stats := []*proto.Stat{} - for _, containers := range pods { - for _, container := range containers.Containers { + for _, pod := range pods { + for _, container := range pod.Containers { if container.Metrics == nil { continue } @@ -163,6 +165,8 @@ func (r *Registrator) Stats(ctx context.Context, in *proto.StatsRequest) (reply stat := &proto.Stat{ Namespace: in.Namespace, Id: container.Display, + PodId: pod.Name, + Name: container.Name, MemoryUsage: used, CpuUsage: data.CPU.Usage.Total, } diff --git a/internal/app/osd/proto/api.proto b/internal/app/osd/proto/api.proto index e5148502e..1d3a6d432 100644 --- a/internal/app/osd/proto/api.proto +++ b/internal/app/osd/proto/api.proto @@ -35,6 +35,8 @@ message Process { string image = 3; uint32 pid = 4; string status = 5; + string pod_id = 6; + string name = 7; } // The request message containing the containerd namespace. @@ -49,6 +51,8 @@ message Stat { string id = 2; uint64 memory_usage = 4; uint64 cpu_usage = 5; + string pod_id = 6; + string name = 7; } // The request message containing the process to restart. @@ -86,7 +90,7 @@ message Route { // Gateway is the gateway address to which traffic to this destination should be sent string gateway = 3; - + // Metric is the priority of the route, where lower metrics have higher priorities uint32 metric = 4;