mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
change to top
This commit is contained in:
parent
648c4f198b
commit
11e28842ac
9 changed files with 23 additions and 23 deletions
6
api.go
6
api.go
|
@ -250,12 +250,12 @@ func getContainersChanges(srv *Server, version float64, w http.ResponseWriter, r
|
|||
return nil
|
||||
}
|
||||
|
||||
func getContainersProc(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
func getContainersTop(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
if vars == nil {
|
||||
return fmt.Errorf("Missing parameter")
|
||||
}
|
||||
name := vars["name"]
|
||||
procsStr, err := srv.ContainerProc(name)
|
||||
procsStr, err := srv.ContainerTop(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -859,7 +859,7 @@ func createRouter(srv *Server, logging bool) (*mux.Router, error) {
|
|||
"/containers/{name:.*}/export": getContainersExport,
|
||||
"/containers/{name:.*}/changes": getContainersChanges,
|
||||
"/containers/{name:.*}/json": getContainersByName,
|
||||
"/containers/{name:.*}/proc": getContainersProc,
|
||||
"/containers/{name:.*}/top": getContainersTop,
|
||||
},
|
||||
"POST": {
|
||||
"/auth": postAuth,
|
||||
|
|
|
@ -26,7 +26,7 @@ type APIInfo struct {
|
|||
SwapLimit bool `json:",omitempty"`
|
||||
}
|
||||
|
||||
type APIProc struct {
|
||||
type APITop struct {
|
||||
PID string
|
||||
Tty string
|
||||
Time string
|
||||
|
|
|
@ -475,7 +475,7 @@ func TestGetContainersChanges(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestGetContainersProc(t *testing.T) {
|
||||
func TestGetContainersTop(t *testing.T) {
|
||||
runtime, err := newTestRuntime()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -509,10 +509,10 @@ func TestGetContainersProc(t *testing.T) {
|
|||
}
|
||||
|
||||
r := httptest.NewRecorder()
|
||||
if err := getContainersProc(srv, APIVERSION, r, nil, map[string]string{"name": container.ID}); err != nil {
|
||||
if err := getContainersTop(srv, APIVERSION, r, nil, map[string]string{"name": container.ID}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
procs := []APIProc{}
|
||||
procs := []APITop{}
|
||||
if err := json.Unmarshal(r.Body.Bytes(), &procs); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
10
commands.go
10
commands.go
|
@ -90,7 +90,7 @@ func (cli *DockerCli) CmdHelp(args ...string) error {
|
|||
{"login", "Register or Login to the docker registry server"},
|
||||
{"logs", "Fetch the logs of a container"},
|
||||
{"port", "Lookup the public-facing port which is NAT-ed to PRIVATE_PORT"},
|
||||
{"proc", "Lookup the running processes of a container"},
|
||||
{"top", "Lookup the running processes of a container"},
|
||||
{"ps", "List containers"},
|
||||
{"pull", "Pull an image or a repository from the docker registry server"},
|
||||
{"push", "Push an image or a repository to the docker registry server"},
|
||||
|
@ -556,8 +556,8 @@ func (cli *DockerCli) CmdInspect(args ...string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (cli *DockerCli) CmdProc(args ...string) error {
|
||||
cmd := Subcmd("proc", "CONTAINER", "Lookup the running processes of a container")
|
||||
func (cli *DockerCli) CmdTop(args ...string) error {
|
||||
cmd := Subcmd("top", "CONTAINER", "Lookup the running processes of a container")
|
||||
if err := cmd.Parse(args); err != nil {
|
||||
return nil
|
||||
}
|
||||
|
@ -565,11 +565,11 @@ func (cli *DockerCli) CmdProc(args ...string) error {
|
|||
cmd.Usage()
|
||||
return nil
|
||||
}
|
||||
body, _, err := cli.call("GET", "/containers/"+cmd.Arg(0)+"/proc", nil)
|
||||
body, _, err := cli.call("GET", "/containers/"+cmd.Arg(0)+"/top", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var procs []APIProc
|
||||
var procs []APITop
|
||||
err = json.Unmarshal(body, &procs)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -29,7 +29,7 @@ You can still call an old version of the api using /v1.0/images/<name>/insert
|
|||
What's new
|
||||
----------
|
||||
|
||||
Listing processes (/proc):
|
||||
Listing processes (/top):
|
||||
|
||||
- List the processes inside a container
|
||||
|
||||
|
|
|
@ -223,7 +223,7 @@ Inspect a container
|
|||
List processes running inside a container
|
||||
*****************************************
|
||||
|
||||
.. http:get:: /containers/(id)/proc
|
||||
.. http:get:: /containers/(id)/top
|
||||
|
||||
List processes running inside the container ``id``
|
||||
|
||||
|
@ -231,7 +231,7 @@ List processes running inside a container
|
|||
|
||||
.. sourcecode:: http
|
||||
|
||||
GET /containers/4fa6e0f0c678/proc HTTP/1.1
|
||||
GET /containers/4fa6e0f0c678/top HTTP/1.1
|
||||
|
||||
**Example response**:
|
||||
|
||||
|
|
|
@ -41,7 +41,6 @@ Available Commands
|
|||
command/login
|
||||
command/logs
|
||||
command/port
|
||||
command/proc
|
||||
command/ps
|
||||
command/pull
|
||||
command/push
|
||||
|
@ -53,5 +52,6 @@ Available Commands
|
|||
command/start
|
||||
command/stop
|
||||
command/tag
|
||||
command/top
|
||||
command/version
|
||||
command/wait
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
:title: Proc Command
|
||||
:title: Top Command
|
||||
:description: Lookup the running processes of a container
|
||||
:keywords: proc, docker, container, documentation
|
||||
:keywords: top, docker, container, documentation
|
||||
|
||||
=======================================================
|
||||
``proc`` -- Lookup the running processes of a container
|
||||
``top`` -- Lookup the running processes of a container
|
||||
=======================================================
|
||||
|
||||
::
|
||||
|
||||
Usage: docker proc CONTAINER
|
||||
Usage: docker top CONTAINER
|
||||
|
||||
Lookup the running processes of a container
|
|
@ -249,18 +249,18 @@ func (srv *Server) ImageHistory(name string) ([]APIHistory, error) {
|
|||
|
||||
}
|
||||
|
||||
func (srv *Server) ContainerProc(name string) ([]APIProc, error) {
|
||||
func (srv *Server) ContainerTop(name string) ([]APITop, error) {
|
||||
if container := srv.runtime.Get(name); container != nil {
|
||||
output, err := exec.Command("lxc-ps", "--name", container.ID).CombinedOutput()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error trying to use lxc-ps: %s (%s)", err, output)
|
||||
}
|
||||
var procs []APIProc
|
||||
var procs []APITop
|
||||
for i, line := range strings.Split(string(output), "\n") {
|
||||
if i == 0 || len(line) == 0 {
|
||||
continue
|
||||
}
|
||||
proc := APIProc{}
|
||||
proc := APITop{}
|
||||
scanner := bufio.NewScanner(strings.NewReader(line))
|
||||
scanner.Split(bufio.ScanWords)
|
||||
if !scanner.Scan() {
|
||||
|
|
Loading…
Reference in a new issue