/
task_ps.go
72 lines (58 loc) · 1.36 KB
/
task_ps.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package cmd
import (
"fmt"
"os"
"text/tabwriter"
"github.com/jpignata/fargate/console"
EC2 "github.com/jpignata/fargate/ec2"
ECS "github.com/jpignata/fargate/ecs"
"github.com/jpignata/fargate/util"
"github.com/spf13/cobra"
)
type TaskProcessListOperation struct {
TaskName string
}
var taskPsCmd = &cobra.Command{
Use: "ps <task name>",
Short: "List running tasks",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
operation := &TaskProcessListOperation{
TaskName: args[0],
}
getTaskProcessList(operation)
},
}
func init() {
taskCmd.AddCommand(taskPsCmd)
}
func getTaskProcessList(operation *TaskProcessListOperation) {
var eniIds []string
ecs := ECS.New(sess, clusterName)
ec2 := EC2.New(sess)
tasks := ecs.DescribeTasksForTaskGroup(operation.TaskName)
for _, task := range tasks {
if task.EniId != "" {
eniIds = append(eniIds, task.EniId)
}
}
if len(tasks) == 0 {
console.InfoExit("No tasks found")
}
enis := ec2.DescribeNetworkInterfaces(eniIds)
w := new(tabwriter.Writer)
w.Init(os.Stdout, 0, 8, 1, '\t', 0)
fmt.Fprintln(w, "ID\tIMAGE\tSTATUS\tRUNNING\tIP\tCPU\tMEMORY\t")
for _, t := range tasks {
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
t.TaskId,
t.Image,
util.Humanize(t.LastStatus),
t.RunningFor(),
enis[t.EniId].PublicIpAddress,
t.Cpu,
t.Memory,
)
}
w.Flush()
}