summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2019-02-25 14:26:18 -0600
committerbaude <bbaude@redhat.com>2019-03-06 11:01:25 -0600
commit788f818cc53fbd68267c2c6ab5de8655938414cb (patch)
tree34f10bb4c0f1153e99524070b3d8da63d975ea42 /cmd
parent7418ff988b520466d04cacf6d88b50d67bfa8ddf (diff)
downloadpodman-788f818cc53fbd68267c2c6ab5de8655938414cb.tar.gz
podman-788f818cc53fbd68267c2c6ab5de8655938414cb.tar.bz2
podman-788f818cc53fbd68267c2c6ab5de8655938414cb.zip
podman-remote pod top|stats
this is the final enablement for the pod subcommand. it includes the ability to run podman-remote pod top and stats. Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/commands.go8
-rw-r--r--cmd/podman/commands_remoteclient.go5
-rw-r--r--cmd/podman/pod.go3
-rw-r--r--cmd/podman/pod_stats.go47
-rw-r--r--cmd/podman/pod_top.go31
-rw-r--r--cmd/podman/varlink/io.podman.varlink7
6 files changed, 27 insertions, 74 deletions
diff --git a/cmd/podman/commands.go b/cmd/podman/commands.go
index c261e54e2..483ada332 100644
--- a/cmd/podman/commands.go
+++ b/cmd/podman/commands.go
@@ -85,14 +85,6 @@ func getContainerSubCommands() []*cobra.Command {
}
}
-// Commands that the local client implements
-func getPodSubCommands() []*cobra.Command {
- return []*cobra.Command{
- _podStatsCommand,
- _podTopCommand,
- }
-}
-
func getGenerateSubCommands() []*cobra.Command {
return []*cobra.Command{
_containerKubeCommand,
diff --git a/cmd/podman/commands_remoteclient.go b/cmd/podman/commands_remoteclient.go
index 081043b25..a278761c1 100644
--- a/cmd/podman/commands_remoteclient.go
+++ b/cmd/podman/commands_remoteclient.go
@@ -29,11 +29,6 @@ func getContainerSubCommands() []*cobra.Command {
}
// commands that only the remoteclient implements
-func getPodSubCommands() []*cobra.Command {
- return []*cobra.Command{}
-}
-
-// commands that only the remoteclient implements
func getGenerateSubCommands() []*cobra.Command {
return []*cobra.Command{}
}
diff --git a/cmd/podman/pod.go b/cmd/podman/pod.go
index c1350bd4d..7067f2429 100644
--- a/cmd/podman/pod.go
+++ b/cmd/podman/pod.go
@@ -29,12 +29,13 @@ var podSubCommands = []*cobra.Command{
_podRestartCommand,
_podRmCommand,
_podStartCommand,
+ _podStatsCommand,
_podStopCommand,
+ _podTopCommand,
_podUnpauseCommand,
}
func init() {
podCommand.AddCommand(podSubCommands...)
- podCommand.AddCommand(getPodSubCommands()...)
podCommand.SetUsageTemplate(UsageTemplate())
}
diff --git a/cmd/podman/pod_stats.go b/cmd/podman/pod_stats.go
index f5edd21f8..2761ce9cc 100644
--- a/cmd/podman/pod_stats.go
+++ b/cmd/podman/pod_stats.go
@@ -13,8 +13,8 @@ import (
tm "github.com/buger/goterm"
"github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/cmd/podman/formats"
- "github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/containers/libpod/libpod"
+ "github.com/containers/libpod/pkg/adapter"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/ulule/deepcopier"
@@ -51,10 +51,6 @@ func init() {
}
func podStatsCmd(c *cliconfig.PodStatsValues) error {
- var (
- podFunc func() ([]*libpod.Pod, error)
- )
-
format := c.Format
all := c.All
latest := c.Latest
@@ -76,7 +72,7 @@ func podStatsCmd(c *cliconfig.PodStatsValues) error {
all = true
}
- runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
+ runtime, err := adapter.GetRuntime(&c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "could not get runtime")
}
@@ -87,29 +83,12 @@ func podStatsCmd(c *cliconfig.PodStatsValues) error {
times = 1
}
- if len(c.InputArgs) > 0 {
- podFunc = func() ([]*libpod.Pod, error) { return getPodsByList(c.InputArgs, runtime) }
- } else if latest {
- podFunc = func() ([]*libpod.Pod, error) {
- latestPod, err := runtime.GetLatestPod()
- if err != nil {
- return nil, err
- }
- return []*libpod.Pod{latestPod}, err
- }
- } else if all {
- podFunc = runtime.GetAllPods
- } else {
- podFunc = runtime.GetRunningPods
- }
-
- pods, err := podFunc()
+ pods, err := runtime.GetStatPods(c)
if err != nil {
return errors.Wrapf(err, "unable to get a list of pods")
}
-
// First we need to get an initial pass of pod/ctr stats (these are not printed)
- var podStats []*libpod.PodContainerStats
+ var podStats []*adapter.PodContainerStats
for _, p := range pods {
cons, err := p.AllContainersByID()
if err != nil {
@@ -120,7 +99,7 @@ func podStatsCmd(c *cliconfig.PodStatsValues) error {
for _, c := range cons {
emptyStats[c] = &libpod.ContainerStats{}
}
- ps := libpod.PodContainerStats{
+ ps := adapter.PodContainerStats{
Pod: p,
ContainerStats: emptyStats,
}
@@ -128,10 +107,10 @@ func podStatsCmd(c *cliconfig.PodStatsValues) error {
}
// Create empty container stat results for our first pass
- var previousPodStats []*libpod.PodContainerStats
+ var previousPodStats []*adapter.PodContainerStats
for _, p := range pods {
cs := make(map[string]*libpod.ContainerStats)
- pcs := libpod.PodContainerStats{
+ pcs := adapter.PodContainerStats{
Pod: p,
ContainerStats: cs,
}
@@ -164,7 +143,7 @@ func podStatsCmd(c *cliconfig.PodStatsValues) error {
}
for i := 0; i < times; i += step {
- var newStats []*libpod.PodContainerStats
+ var newStats []*adapter.PodContainerStats
for _, p := range pods {
prevStat := getPreviousPodContainerStats(p.ID(), previousPodStats)
newPodStats, err := p.GetPodStats(prevStat)
@@ -174,7 +153,7 @@ func podStatsCmd(c *cliconfig.PodStatsValues) error {
if err != nil {
return err
}
- newPod := libpod.PodContainerStats{
+ newPod := adapter.PodContainerStats{
Pod: p,
ContainerStats: newPodStats,
}
@@ -202,7 +181,7 @@ func podStatsCmd(c *cliconfig.PodStatsValues) error {
time.Sleep(time.Second)
previousPodStats := new([]*libpod.PodContainerStats)
deepcopier.Copy(newStats).To(previousPodStats)
- pods, err = podFunc()
+ pods, err = runtime.GetStatPods(c)
if err != nil {
return err
}
@@ -211,7 +190,7 @@ func podStatsCmd(c *cliconfig.PodStatsValues) error {
return nil
}
-func podContainerStatsToPodStatOut(stats []*libpod.PodContainerStats) []*podStatOut {
+func podContainerStatsToPodStatOut(stats []*adapter.PodContainerStats) []*podStatOut {
var out []*podStatOut
for _, p := range stats {
for _, c := range p.ContainerStats {
@@ -295,7 +274,7 @@ func outputToStdOut(stats []*podStatOut) {
w.Flush()
}
-func getPreviousPodContainerStats(podID string, prev []*libpod.PodContainerStats) map[string]*libpod.ContainerStats {
+func getPreviousPodContainerStats(podID string, prev []*adapter.PodContainerStats) map[string]*libpod.ContainerStats {
for _, p := range prev {
if podID == p.Pod.ID() {
return p.ContainerStats
@@ -304,7 +283,7 @@ func getPreviousPodContainerStats(podID string, prev []*libpod.PodContainerStats
return map[string]*libpod.ContainerStats{}
}
-func outputJson(stats []*libpod.PodContainerStats) error {
+func outputJson(stats []*adapter.PodContainerStats) error {
b, err := json.MarshalIndent(&stats, "", " ")
if err != nil {
return err
diff --git a/cmd/podman/pod_top.go b/cmd/podman/pod_top.go
index 6a26e3dff..c5383d376 100644
--- a/cmd/podman/pod_top.go
+++ b/cmd/podman/pod_top.go
@@ -2,13 +2,12 @@ package main
import (
"fmt"
+ "github.com/containers/libpod/pkg/adapter"
"os"
"strings"
"text/tabwriter"
"github.com/containers/libpod/cmd/podman/cliconfig"
- "github.com/containers/libpod/cmd/podman/libpodruntime"
- "github.com/containers/libpod/cmd/podman/shared"
"github.com/containers/libpod/libpod"
"github.com/pkg/errors"
"github.com/spf13/cobra"
@@ -50,8 +49,9 @@ func init() {
}
func podTopCmd(c *cliconfig.PodTopValues) error {
- var pod *libpod.Pod
- var err error
+ var (
+ descriptors []string
+ )
args := c.InputArgs
if c.ListDescriptors {
@@ -67,39 +67,22 @@ func podTopCmd(c *cliconfig.PodTopValues) error {
return errors.Errorf("you must provide the name or id of a running pod")
}
- runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
+ runtime, err := adapter.GetRuntime(&c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "error creating libpod runtime")
}
defer runtime.Shutdown(false)
- var descriptors []string
if c.Latest {
descriptors = args
- pod, err = runtime.GetLatestPod()
} else {
descriptors = args[1:]
- pod, err = runtime.LookupPod(args[0])
}
-
- if err != nil {
- return errors.Wrapf(err, "unable to lookup requested container")
- }
-
- podStatus, err := shared.GetPodStatus(pod)
- if err != nil {
- return err
- }
- if podStatus != "Running" {
- return errors.Errorf("pod top can only be used on pods with at least one running container")
- }
-
- psOutput, err := pod.GetPodPidInformation(descriptors)
+ w := tabwriter.NewWriter(os.Stdout, 5, 1, 3, ' ', 0)
+ psOutput, err := runtime.PodTop(c, descriptors)
if err != nil {
return err
}
-
- w := tabwriter.NewWriter(os.Stdout, 5, 1, 3, ' ', 0)
for _, proc := range psOutput {
fmt.Fprintln(w, proc)
}
diff --git a/cmd/podman/varlink/io.podman.varlink b/cmd/podman/varlink/io.podman.varlink
index 73e6c15f9..a50b7dd13 100644
--- a/cmd/podman/varlink/io.podman.varlink
+++ b/cmd/podman/varlink/io.podman.varlink
@@ -549,6 +549,10 @@ method ExportContainer(name: string, path: string) -> (tarfile: string)
# ~~~
method GetContainerStats(name: string) -> (container: ContainerStats)
+# GetContainerStatsWithHistory takes a previous set of container statistics and uses libpod functions
+# to calculate the containers statistics based on current and previous measurements.
+method GetContainerStatsWithHistory(previousStats: ContainerStats) -> (container: ContainerStats)
+
# This method has not be implemented yet.
# method ResizeContainerTty() -> (notimplemented: NotImplemented)
@@ -952,8 +956,7 @@ method RemovePod(name: string, force: bool) -> (pod: string)
# This method has not be implemented yet.
# method WaitPod() -> (notimplemented: NotImplemented)
-# This method has not been implemented yet.
-# method TopPod() -> (notimplemented: NotImplemented)
+method TopPod(pod: string, latest: bool, descriptors: []string) -> (stats: []string)
# GetPodStats takes the name or ID of a pod and returns a pod name and slice of ContainerStats structure which
# contains attributes like memory and cpu usage. If the pod cannot be found, a [PodNotFound](#PodNotFound)