Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12241371
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/cmd/containersps/containersps.go b/cmd/containersps/containersps.go
index 9fd8f54..b4cd94e 100644
--- a/cmd/containersps/containersps.go
+++ b/cmd/containersps/containersps.go
@@ -1,62 +1,61 @@
package main
import (
"context"
"devcentral.nasqueron.org/source/docker-processes/pkg/dockerutils"
"devcentral.nasqueron.org/source/docker-processes/pkg/process"
"fmt"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"log"
"os"
)
const DockerApiVersion = "1.37"
func main() {
dockerClient, err := client.NewClientWithOpts(client.WithVersion(DockerApiVersion))
if err != nil {
log.Println("Can't connect to Docker engine.")
os.Exit(1)
}
containers, err := dockerClient.ContainerList(context.Background(), types.ContainerListOptions{})
if err != nil {
panic(err)
}
fmt.Printf("%s\n", getProcessLineTitle())
psArgs := []string{"auxw"}
for _, container := range containers {
name := dockerutils.GetContainerName(container)
response, err := dockerClient.ContainerTop(context.Background(), container.ID, psArgs)
if err != nil {
continue
}
for _, containerProcess := range response.Processes {
processInfo := process.Parse(response.Titles, containerProcess)
processLine := getProcessLine(name, processInfo)
fmt.Printf("%s\n", processLine)
}
}
}
func getProcessLineTitle() string {
return "CONTAINER USER PID %CPU VSZ RSS COMMAND"
}
func getProcessLineFormat() string {
return "%20s %9s %6d %.2f %8d %8d %s"
}
func getProcessLine(containerName string, processInfo process.Process) string {
format := getProcessLineFormat()
return fmt.Sprintf(
format,
containerName, processInfo.User, processInfo.Pid, processInfo.CPU,
processInfo.VSZ, processInfo.RSS, processInfo.Command)
}
-
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Oct 12, 05:02 (6 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3065063
Default Alt Text
(1 KB)
Attached To
Mode
rDP Docker Processes
Attached
Detach File
Event Timeline
Log In to Comment