Skip to content

Commit

Permalink
Cleaned cluster output. Added install script. Removed goterm dep
Browse files Browse the repository at this point in the history
  • Loading branch information
colinmutter committed Mar 4, 2016
1 parent 19283a7 commit b13aa37
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ _testmain.go
*.prof

vendor/
build/
52 changes: 51 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,52 @@
# go-ecs
A go utility for viewing status/config of AWS ECS cluster(s)

go-ecs is a simple command line utility to view [AWS ECS](https://aws.amazon.com/ecs/) cluster status quickly.

## Installation

On OS X or Linux:

```
curl https://raw.githubusercontent.com/colinmutter/go-ecs/master/install.sh | sh
```

On Windows download [binary](https://github.com/colinmutter/go-ecs/releases).

## Usage

```
go-ecs [options]
-p profile aws profile name
```

## Configuration
An IAM Policy will need to be created, or the following permissions granted to allow this utility to function.

```
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ecs:DescribeClusters",
"ecs:DescribeContainerInstances",
"ecs:DescribeServices",
"ecs:DescribeTaskDefinition",
"ecs:DescribeTasks",
"ecs:DiscoverPollEndpoint",
"ecs:ListClusters",
"ecs:ListContainerInstances",
"ecs:ListServices",
"ecs:ListTaskDefinitions",
"ecs:ListTasks",
"ecs:Poll",
"ec2:DescribeInstances"
],
"Resource": [
"*"
]
}
]
}
```
8 changes: 5 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,17 @@ func getSessionWithConfig(config *aws.Config) (*session.Session, error) {
region, err := getAWSRegion()

if profileName != "" {
fmt.Println("Using profile: ", *profile)
fmt.Println("Profile: ", *profile)
} else {
fmt.Println("Using profile: default")
fmt.Println("Profile: default")
}

if region != "" {
fmt.Println("With region: ", region)
fmt.Println("Region: ", region)
config = config.WithRegion(region)
}

fmt.Println()
return session.New(config), err
}

Expand Down
37 changes: 20 additions & 17 deletions ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/ecs"
"github.com/buger/goterm"
"github.com/olekukonko/tablewriter"
)

Expand Down Expand Up @@ -63,9 +62,6 @@ func main() {
return
}

goterm.Clear()
goterm.Flush()

// Get lots of extra data by cluster
for _, thisCluster := range clusters {

Expand Down Expand Up @@ -104,21 +100,28 @@ func main() {
clusterContainerInstances = clusterContainerInstances
ec2Instances = ec2Instances

fmt.Println(strings.Repeat("_", goterm.Width()))
clusterName := fmt.Sprintf("Cluster:\t%s", *clusterStatus.ClusterName)
fmt.Println(clusterName)
fmt.Println(strings.Repeat("-", len(clusterName)+8))
fmt.Printf("-Status:\t%s\n", *clusterStatus.Status)
fmt.Printf("-Pending Tasks:\t%d\n", *clusterStatus.PendingTasksCount)
fmt.Printf("-Running Tasks:\t%d\n", *clusterStatus.RunningTasksCount)
fmt.Printf("-Instances:\t%d\n", *clusterStatus.RegisteredContainerInstancesCount)
fmt.Println()

// Pretty-print the response data.
clusterTable := tablewriter.NewWriter(os.Stdout)
clusterTable.SetHeader([]string{"Cluster", "Status", "Pending Tasks", "Running Tasks", "Container Instances"})
clusterTable.SetRowSeparator("-")
clusterTable.Append([]string{
*clusterStatus.ClusterName,
*clusterStatus.Status,
fmt.Sprintf("%d", *clusterStatus.PendingTasksCount),
fmt.Sprintf("%d", *clusterStatus.RunningTasksCount),
fmt.Sprintf("%d", *clusterStatus.RegisteredContainerInstancesCount),
})
clusterTable.Render()
fmt.Println()
// clusterTable := tablewriter.NewWriter(os.Stdout)
// clusterTable.SetHeader([]string{"Cluster", "Status", "Pending Tasks", "Running Tasks", "Container Instances"})
// clusterTable.SetRowSeparator("-")
// clusterTable.Append([]string{
// *clusterStatus.ClusterName,
// *clusterStatus.Status,
// fmt.Sprintf("%d", *clusterStatus.PendingTasksCount),
// fmt.Sprintf("%d", *clusterStatus.RunningTasksCount),
// fmt.Sprintf("%d", *clusterStatus.RegisteredContainerInstancesCount),
// })
// clusterTable.Render()
// fmt.Println()

serviceTable := tablewriter.NewWriter(os.Stdout)
serviceTable.SetHeader([]string{"Service", "Status", "Task Def", "Tasks Running/Pending", "Deployments Running/Pending", "Last Updated"})
Expand Down
46 changes: 46 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh

install () {

set -eu

PROJECT="go-ecs"
REPO="colinmutter/go-ecs"

GITHUB_URL="https://github.com/${REPO}"
RELEASES_URL="${GITHUB_URL}/releases"
UNAME=$(uname)
if [ "$UNAME" != "Linux" -a "$UNAME" != "Darwin" ] ; then
echo "Sorry, OS not supported: ${UNAME}. Download binary from ${RELEASES_URL}"
exit 1
fi

if [ "$UNAME" = "Darwin" ] ; then
OSX_ARCH=$(uname -m)
if [ "${OSX_ARCH}" = "x86_64" ] ; then
PLATFORM="darwin_amd64"
else
echo "Sorry, architecture not supported: ${OSX_ARCH}. Download binary from ${RELEASES_URL}"
exit 1
fi
elif [ "$UNAME" = "Linux" ] ; then
LINUX_ARCH=$(uname -m)
if [ "${LINUX_ARCH}" = "i686" ] ; then
PLATFORM="linux_386"
elif [ "${LINUX_ARCH}" = "x86_64" ] ; then
PLATFORM="linux_amd64"
else
echo "Sorry, architecture not supported: ${LINUX_ARCH}. Download binary from ${RELEASES_URL}"
exit 1
fi
fi

LATEST=$(curl -s https://api.github.com/repos/${REPO}/tags | grep name | head -n 1 | sed 's/[," ]//g' | cut -d ':' -f 2)
URL="${RELEASES_URL}/download/$LATEST/${PROJECT}_$PLATFORM"

curl -sL ${RELEASES_URL}/download/$LATEST/${PROJECT}_$PLATFORM -o /usr/local/bin/${PROJECT}
chmod +x $_

}

install

0 comments on commit b13aa37

Please sign in to comment.