1
0
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:
Paul-Christian Volkmer 2022-12-25 11:29:19 +01:00
parent 1be4efc450
commit c9712d8876

21
main.go
View File

@ -74,9 +74,24 @@ func getProcesses(dc *client.Client) ([]Process, error) {
if containers, err := dc.ContainerList(context.Background(), types.ContainerListOptions{All: true}); err == nil {
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{})
if err != nil {
continue
return nil, err
}
uid := 0
@ -103,10 +118,6 @@ func getProcesses(dc *client.Client) ([]Process, error) {
Command: process[cmd],
})
}
}
} else {
return nil, err
}
return processes, nil
}