Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Commit

Permalink
Tfhartmann/plat 2103 send ecs cluster data to cloudwatch (#2)
Browse files Browse the repository at this point in the history
* Adding Script to send metrics into cloudwatch

* Update to ECS Cluster Service

to add a job to send metrics to cloudwatch

* Updated command

Included timestamp

* Added Unit and more Dimensions

* Adding instance ID

* Adding some logging

Also changing up what the metric is by removing dimensions

* Change to count registered instances

* comment out unused var

Since we aren't using that var at the moment, I commented it out, this
should also make the runtime faster

* Adding CODEOWNERS File

* Oh... I'm going to feel so dumb.

* Adding back ContainerInstancesCount
  • Loading branch information
tfhartmann authored Mar 2, 2018
1 parent 9893f60 commit 71e3ab6
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This is a comment.
# Each line is a file pattern followed by one or more owners.

# These owners will be the default owners for everything in
# the repo. Unless a later match takes precedence,
# @global-owner1 and @global-owner2 will be requested for
# review when someone opens a pull request.
#* @global-owner1 @global-owner2
* @FitnessKeeper/devops

# Order is important; the last matching pattern takes the most
# precedence. When someone opens a pull request that only
# modifies JS files, only @js-owner and not the global
# owner(s) will be requested for a review.
#*.js @js-owner

# You can also use email addresses if you prefer. They'll be
# used to look up users just like we do for commit author
# emails.
#*.go [email protected]

# In this example, @doctocat owns any files in the build/logs
# directory at the root of the repository and any of its
# subdirectories.
#/build/logs/ @doctocat

# The `docs/*` pattern will match files like
# `docs/getting-started.md` but not further nested files like
# `docs/build-app/troubleshooting.md`.
#docs/* [email protected]

# In this example, @octocat owns any file in an apps directory
# anywhere in your repository.
#apps/ @octocat

# In this example, @doctocat owns any file in the `/docs`
# directory in the root of your repository.
#/docs/ @doctocat
11 changes: 11 additions & 0 deletions check_definitions/ecs-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,18 @@ _SERVICE=$(cat <<EOT
"args": ["/usr/local/bin/ami_up2date.sh"],
"interval": "10s",
"status": "passing"
},
{
"id": "ecs-cloudwatch",
"name": "ECS CloudWatch",
"notes": "Send Metrics to CloudWatch",
"docker_container_id": "${DOCKER_ID}",
"shell": "/bin/bash",
"args": ["/usr/local/bin/ecs-cloudwatch-metrics.sh"],
"interval": "60s",
"status": "passing"
}
]
}
}
Expand Down
16 changes: 16 additions & 0 deletions scripts/ecs-cloudwatch-metrics.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
#Usage:
# Push metrics into cloudwatch

#./ecs-cloudwatch-metric.sh
#

REGION=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone/ | sed 's/.$//')
ECS_CLUSTER=$(curl -s http://localhost:51678/v1/metadata | jq -r .Cluster)
#ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
CONTAINERINSTANCES=$(aws --region ${REGION} ecs describe-clusters --clusters ${ECS_CLUSTER} | jq .clusters[0].registeredContainerInstancesCount)
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")

aws --region ${REGION} cloudwatch put-metric-data --metric-name ContainerInstancesCount --namespace /AWS/ECS --dimensions Cluster=${ECS_CLUSTER} --unit Count --value 1 --timestamp ${TIMESTAMP}
aws --region ${REGION} cloudwatch put-metric-data --metric-name registeredContainerInstances --namespace /AWS/ECS --dimensions Cluster=${ECS_CLUSTER} --unit Count --value ${CONTAINERINSTANCES} --timestamp ${TIMESTAMP}
exit 0

0 comments on commit 71e3ab6

Please sign in to comment.