2018-02-05 16:05:59 -05:00
|
|
|
package client // import "github.com/docker/docker/client"
|
2016-09-06 14:46:37 -04:00
|
|
|
|
|
|
|
import (
|
2018-04-19 18:30:59 -04:00
|
|
|
"context"
|
2016-09-06 14:46:37 -04:00
|
|
|
"encoding/json"
|
|
|
|
"net/url"
|
|
|
|
"strings"
|
|
|
|
|
2016-11-14 14:50:16 -05:00
|
|
|
"github.com/docker/docker/api/types/container"
|
2016-09-06 14:46:37 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// ContainerTop shows process information from within a container.
|
2016-11-14 14:50:16 -05:00
|
|
|
func (cli *Client) ContainerTop(ctx context.Context, containerID string, arguments []string) (container.ContainerTopOKBody, error) {
|
|
|
|
var response container.ContainerTopOKBody
|
2016-09-06 14:46:37 -04:00
|
|
|
query := url.Values{}
|
|
|
|
if len(arguments) > 0 {
|
|
|
|
query.Set("ps_args", strings.Join(arguments, " "))
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := cli.get(ctx, "/containers/"+containerID+"/top", query, nil)
|
2019-02-11 07:26:12 -05:00
|
|
|
defer ensureReaderClosed(resp)
|
2016-09-06 14:46:37 -04:00
|
|
|
if err != nil {
|
|
|
|
return response, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = json.NewDecoder(resp.body).Decode(&response)
|
|
|
|
return response, err
|
|
|
|
}
|