mirror of
https://github.com/pcvolkmer/docker-pps.git
synced 2025-04-19 17:56:50 +00:00
Extract method to fetch container processes
This commit is contained in:
parent
1be4efc450
commit
c9712d8876
21
main.go
21
main.go
@ -74,9 +74,24 @@ func getProcesses(dc *client.Client) ([]Process, error) {
|
|||||||
|
|
||||||
if containers, err := dc.ContainerList(context.Background(), types.ContainerListOptions{All: true}); err == nil {
|
if containers, err := dc.ContainerList(context.Background(), types.ContainerListOptions{All: true}); err == nil {
|
||||||
for _, container := range containers {
|
for _, container := range containers {
|
||||||
|
if containerProcesses, err := containerProcesses(dc, container); err == nil {
|
||||||
|
processes = append(processes, containerProcesses...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return processes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get all processes running in current docker container
|
||||||
|
func containerProcesses(dc *client.Client, container types.Container) ([]Process, error) {
|
||||||
|
var processes []Process
|
||||||
|
|
||||||
tops, err := dc.ContainerTop(context.Background(), container.ID, []string{})
|
tops, err := dc.ContainerTop(context.Background(), container.ID, []string{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
uid := 0
|
uid := 0
|
||||||
@ -103,10 +118,6 @@ func getProcesses(dc *client.Client) ([]Process, error) {
|
|||||||
Command: process[cmd],
|
Command: process[cmd],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return processes, nil
|
return processes, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user