mirror of
https://github.com/clearlinux/docker.git
synced 2026-10-04 07:48:44 +00:00
Merge pull request #12259 from duglin/RemoveJobTop
Remove Job from `docker top`
This commit is contained in:
+10
-9
@@ -1,12 +1,13 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/docker/docker/engine"
|
||||
"github.com/docker/docker/api/types"
|
||||
flag "github.com/docker/docker/pkg/mflag"
|
||||
)
|
||||
|
||||
@@ -28,17 +29,17 @@ func (cli *DockerCli) CmdTop(args ...string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var procs engine.Env
|
||||
if err := procs.Decode(stream); err != nil {
|
||||
|
||||
procList := types.ContainerProcessList{}
|
||||
err = json.NewDecoder(stream).Decode(&procList)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
w := tabwriter.NewWriter(cli.out, 20, 1, 3, ' ', 0)
|
||||
fmt.Fprintln(w, strings.Join(procs.GetList("Titles"), "\t"))
|
||||
processes := [][]string{}
|
||||
if err := procs.GetJson("Processes", &processes); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, proc := range processes {
|
||||
fmt.Fprintln(w, strings.Join(procList.Titles, "\t"))
|
||||
|
||||
for _, proc := range procList.Processes {
|
||||
fmt.Fprintln(w, strings.Join(proc, "\t"))
|
||||
}
|
||||
w.Flush()
|
||||
|
||||
@@ -490,16 +490,21 @@ func getContainersTop(eng *engine.Engine, version version.Version, w http.Respon
|
||||
if version.LessThan("1.4") {
|
||||
return fmt.Errorf("top was improved a lot since 1.3, Please upgrade your docker client.")
|
||||
}
|
||||
|
||||
if vars == nil {
|
||||
return fmt.Errorf("Missing parameter")
|
||||
}
|
||||
|
||||
if err := parseForm(r); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
job := eng.Job("top", vars["name"], r.Form.Get("ps_args"))
|
||||
streamJSON(job, w, false)
|
||||
return job.Run()
|
||||
procList, err := getDaemon(eng).ContainerTop(vars["name"], r.Form.Get("ps_args"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return writeJSON(w, http.StatusOK, procList)
|
||||
}
|
||||
|
||||
func getContainersJSON(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
|
||||
@@ -104,3 +104,9 @@ type Container struct {
|
||||
type CopyConfig struct {
|
||||
Resource string
|
||||
}
|
||||
|
||||
// GET "/containers/{name:.*}/top"
|
||||
type ContainerProcessList struct {
|
||||
Processes [][]string
|
||||
Titles []string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user