This repository was archived by the owner on May 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathservice_info.go
104 lines (85 loc) · 2.31 KB
/
service_info.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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"
)
var serviceInfoCmd = &cobra.Command{
Use: "info <service name>",
Short: "Display information about a service",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
infoService(args[0])
},
}
func init() {
serviceCmd.AddCommand(serviceInfoCmd)
}
func infoService(serviceName string) {
var eniIds []string
ecs := ECS.New()
ec2 := EC2.New()
service := ecs.DescribeService(serviceName)
tasks := ecs.DescribeTasksForService(serviceName)
for _, task := range tasks {
eniIds = append(eniIds, task.EniId)
}
console.KeyValue("Service Name", "%s\n", serviceName)
console.KeyValue("Status", "\n")
console.KeyValue(" Desired", "%d\n", service.DesiredCount)
console.KeyValue(" Running", "%d\n", service.RunningCount)
console.KeyValue(" Pending", "%d\n", service.PendingCount)
console.KeyValue("Image", "%s\n", service.Image)
console.KeyValue("Cpu", "%s\n", service.Cpu)
console.KeyValue("Memory", "%s\n", service.Memory)
if len(tasks) > 0 {
console.Header("== Tasks ==")
enis := ec2.DescribeNetworkInterfaces(eniIds)
w := new(tabwriter.Writer)
w.Init(os.Stdout, 0, 8, 1, '\t', 0)
fmt.Fprintln(w, "IMAGE\tSTATUS\tDESIRED STATUS\tCREATED\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.Image,
util.Humanize(t.LastStatus),
util.Humanize(t.DesiredStatus),
t.CreatedAt,
enis[t.EniId].PublicIpAddress,
t.Cpu,
t.Memory,
)
}
w.Flush()
}
if len(service.Deployments) > 0 {
console.Header("== Deployments ==")
w := new(tabwriter.Writer)
w.Init(os.Stdout, 0, 8, 1, '\t', 0)
fmt.Fprintln(w, "IMAGE\tSTATUS\tCREATED\tDESIRED\tRUNNING\tPENDING")
for _, d := range service.Deployments {
fmt.Fprintf(w, "%s\t%s\t%s\t%d\t%d\t%d\n",
d.Image,
util.Humanize(d.Status),
d.CreatedAt,
d.DesiredCount,
d.RunningCount,
d.PendingCount,
)
}
w.Flush()
}
if len(service.Events) > 0 {
console.Header("== Events ==")
for i, event := range service.Events {
fmt.Printf("[%s] %s\n", event.CreatedAt, event.Message)
if i == 10 {
break
}
}
}
}