From 69a82cce55a1e0ab07a82ed2b4e2ee48578e5559 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Mon, 23 May 2016 23:36:51 +0000 Subject: [PATCH 1/8] Fixed namespace to be the same as the AWS scripts and added ASG support --- aws-mon.sh | 22 ++++++++++++++++++---- instance-id | 1 + 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 instance-id diff --git a/aws-mon.sh b/aws-mon.sh index 003c15b..753f305 100755 --- a/aws-mon.sh +++ b/aws-mon.sh @@ -23,10 +23,12 @@ SCRIPT_VERSION=1.1 instanceid=`wget -q -O - http://169.254.169.254/latest/meta-data/instance-id` azone=`wget -q -O - http://169.254.169.254/latest/meta-data/placement/availability-zone` region=${azone/%?/} +asg=`aws autoscaling describe-auto-scaling-instances --region $region --instance-ids $instanceid --query "AutoScalingInstances[*].AutoScalingGroupName" --output text` export EC2_REGION=$region +export AWS_DEFAULT_REGION=$region -######################################## +####################################### # Constants ######################################## KILO=1024 @@ -71,6 +73,7 @@ usage() printf " %-28s %s\n" "--disk-space-util" "Reports disk space utilization in percentages." printf " %-28s %s\n" "--disk-space-used" "Reports allocated disk space in gigabytes." printf " %-28s %s\n" "--disk-space-avail" "Reports available disk space in gigabytes." + printf " %-28s %s\n" "--autoscaling" "Reports auto-scaling metrics only." printf " %-28s %s\n" "--all-items" "Reports all items." } @@ -79,7 +82,7 @@ usage() # Options ######################################## SHORT_OPTS="h" -LONG_OPTS="help,version,verify,verbose,debug,from-cron,profile:,load-ave1,load-ave5,load-ave15,interrupt,context-switch,cpu-us,cpu-sy,cpu-id,cpu-wa,cpu-st,memory-units:,mem-used-incl-cache-buff,mem-util,mem-used,mem-avail,swap-util,swap-used,swap-avail,disk-path:,disk-space-units:,disk-space-util,disk-space-used,disk-space-avail,all-items" +LONG_OPTS="help,version,verify,verbose,debug,from-cron,profile:,load-ave1,load-ave5,load-ave15,interrupt,context-switch,cpu-us,cpu-sy,cpu-id,cpu-wa,cpu-st,memory-units:,mem-used-incl-cache-buff,mem-util,mem-used,mem-avail,swap-util,swap-used,swap-avail,disk-path:,disk-space-units:,disk-space-util,disk-space-used,disk-space-avail,autoscaling,ll-items" ARGS=$(getopt -s bash --options $SHORT_OPTS --longoptions $LONG_OPTS --name $SCRIPT_NAME -- "$@" ) @@ -113,6 +116,7 @@ DISK_SPACE_UNIT_DIV=1 DISK_SPACE_UTIL=0 DISK_SPACE_USED=0 DISK_SPACE_AVAIL=0 +ASG_ONLY=0 eval set -- "$ARGS" while true; do @@ -137,6 +141,9 @@ while true; do --from-cron) FROM_CRON=1 ;; + --autoscaling) + ASG_ONLY=1 + ;; # Profile --profile) shift @@ -317,11 +324,18 @@ if [ $FROM_CRON -eq 1 ]; then fi # CloudWatch Command Line Interface Option -CLOUDWATCH_OPTS="--namespace System/Detail/Linux --dimensions InstanceId=$instanceid" +CLOUDWATCH_OPTS="--namespace System/Linux" if [ -n "$PROFILE" ]; then CLOUDWATCH_OPTS="$CLOUDWATCH_OPTS --profile $PROFILE" fi - +#if [ -n "$asg" ] && [ $ASG_ONLY -eq 1]; then +if [ $ASG_ONLY -eq 1 ]; then + asg="test" + CLOUDWATCH_OPTS="$CLOUDWATCH_OPTS --dimensions AutoScalingGroupName=$asg" +else + CLOUDWATCH_OPTS="$CLOUDWATCH_OPTS --dimensions InstanceId=$instanceid" +fi +echo $CLOUDWATCH_OPTS # Command Output if [ $DEBUG -eq 1 ]; then echo "-----loadavg-----" diff --git a/instance-id b/instance-id new file mode 100644 index 0000000..638a6f9 --- /dev/null +++ b/instance-id @@ -0,0 +1 @@ +i-83106d14 \ No newline at end of file From 5aa40eb3fc1bfe8968344f069e8c905c3f19c0e4 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Mon, 23 May 2016 23:38:26 +0000 Subject: [PATCH 2/8] Updated readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 332506c..37bf24d 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,7 @@ Name | Description --disk-space-util | Reports disk space utilization in percentages. --disk-space-used | Reports allocated disk space in gigabytes. --disk-space-avail | Reports available disk space in gigabytes. +--autoscaling | Use this option when reporting metrics for an auto-scaling group --all-items | Reports all items. ### Examples From 8fd133069c8e86f37ff767d92be83a2e38e087d1 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Mon, 23 May 2016 23:40:38 +0000 Subject: [PATCH 3/8] Commented out line used for testing asg reporting --- aws-mon.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aws-mon.sh b/aws-mon.sh index 753f305..6f0ab26 100755 --- a/aws-mon.sh +++ b/aws-mon.sh @@ -328,8 +328,8 @@ CLOUDWATCH_OPTS="--namespace System/Linux" if [ -n "$PROFILE" ]; then CLOUDWATCH_OPTS="$CLOUDWATCH_OPTS --profile $PROFILE" fi -#if [ -n "$asg" ] && [ $ASG_ONLY -eq 1]; then -if [ $ASG_ONLY -eq 1 ]; then +if [ -n "$asg" ] && [ $ASG_ONLY -eq 1]; then +#if [ $ASG_ONLY -eq 1 ]; then asg="test" CLOUDWATCH_OPTS="$CLOUDWATCH_OPTS --dimensions AutoScalingGroupName=$asg" else From c5b21c69f6f3d2d77f7db43946bd9db69ef18bec Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Mon, 23 May 2016 23:41:54 +0000 Subject: [PATCH 4/8] Commented out line used for testing asg reporting --- aws-mon.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws-mon.sh b/aws-mon.sh index 6f0ab26..d090e1b 100755 --- a/aws-mon.sh +++ b/aws-mon.sh @@ -330,7 +330,7 @@ if [ -n "$PROFILE" ]; then fi if [ -n "$asg" ] && [ $ASG_ONLY -eq 1]; then #if [ $ASG_ONLY -eq 1 ]; then - asg="test" + #asg="test" CLOUDWATCH_OPTS="$CLOUDWATCH_OPTS --dimensions AutoScalingGroupName=$asg" else CLOUDWATCH_OPTS="$CLOUDWATCH_OPTS --dimensions InstanceId=$instanceid" From 32f8d1c2b71344598fe65658f6e67e0f25724baf Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Mon, 23 May 2016 23:43:14 +0000 Subject: [PATCH 5/8] Removed lines used for testing --- aws-mon.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/aws-mon.sh b/aws-mon.sh index d090e1b..9136d4f 100755 --- a/aws-mon.sh +++ b/aws-mon.sh @@ -329,13 +329,11 @@ if [ -n "$PROFILE" ]; then CLOUDWATCH_OPTS="$CLOUDWATCH_OPTS --profile $PROFILE" fi if [ -n "$asg" ] && [ $ASG_ONLY -eq 1]; then -#if [ $ASG_ONLY -eq 1 ]; then - #asg="test" CLOUDWATCH_OPTS="$CLOUDWATCH_OPTS --dimensions AutoScalingGroupName=$asg" else - CLOUDWATCH_OPTS="$CLOUDWATCH_OPTS --dimensions InstanceId=$instanceid" + CLOUDWATCH_OPTS="$CLOUDWATCH_OPTS --dimensions InstanceId=$instanceid" fi -echo $CLOUDWATCH_OPTS + # Command Output if [ $DEBUG -eq 1 ]; then echo "-----loadavg-----" From f7d05f7b1fd5145fa7e87edeae8faa2fa5b65451 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Mon, 23 May 2016 23:44:27 +0000 Subject: [PATCH 6/8] Removed instance-id dummy file --- instance-id | 1 - 1 file changed, 1 deletion(-) delete mode 100644 instance-id diff --git a/instance-id b/instance-id deleted file mode 100644 index 638a6f9..0000000 --- a/instance-id +++ /dev/null @@ -1 +0,0 @@ -i-83106d14 \ No newline at end of file From 9df021dcda6265731873b122d72239c0b2e98461 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Sch=C3=BCtte?= Date: Fri, 17 Jun 2016 15:21:29 +0200 Subject: [PATCH 7/8] fix typo --- aws-mon.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws-mon.sh b/aws-mon.sh index 9136d4f..66028d1 100755 --- a/aws-mon.sh +++ b/aws-mon.sh @@ -82,7 +82,7 @@ usage() # Options ######################################## SHORT_OPTS="h" -LONG_OPTS="help,version,verify,verbose,debug,from-cron,profile:,load-ave1,load-ave5,load-ave15,interrupt,context-switch,cpu-us,cpu-sy,cpu-id,cpu-wa,cpu-st,memory-units:,mem-used-incl-cache-buff,mem-util,mem-used,mem-avail,swap-util,swap-used,swap-avail,disk-path:,disk-space-units:,disk-space-util,disk-space-used,disk-space-avail,autoscaling,ll-items" +LONG_OPTS="help,version,verify,verbose,debug,from-cron,profile:,load-ave1,load-ave5,load-ave15,interrupt,context-switch,cpu-us,cpu-sy,cpu-id,cpu-wa,cpu-st,memory-units:,mem-used-incl-cache-buff,mem-util,mem-used,mem-avail,swap-util,swap-used,swap-avail,disk-path:,disk-space-units:,disk-space-util,disk-space-used,disk-space-avail,autoscaling,all-items" ARGS=$(getopt -s bash --options $SHORT_OPTS --longoptions $LONG_OPTS --name $SCRIPT_NAME -- "$@" ) From d1bf6bde173a0953b694d2c8d229a6c52c7f58c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Sch=C3=BCtte?= Date: Tue, 5 Jul 2016 09:45:03 +0200 Subject: [PATCH 8/8] fix typo aws-mon.sh: line 331: [: missing `]' when using --autoscaling --- aws-mon.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws-mon.sh b/aws-mon.sh index 66028d1..128acff 100755 --- a/aws-mon.sh +++ b/aws-mon.sh @@ -328,7 +328,7 @@ CLOUDWATCH_OPTS="--namespace System/Linux" if [ -n "$PROFILE" ]; then CLOUDWATCH_OPTS="$CLOUDWATCH_OPTS --profile $PROFILE" fi -if [ -n "$asg" ] && [ $ASG_ONLY -eq 1]; then +if [ -n "$asg" ] && [ $ASG_ONLY -eq 1 ]; then CLOUDWATCH_OPTS="$CLOUDWATCH_OPTS --dimensions AutoScalingGroupName=$asg" else CLOUDWATCH_OPTS="$CLOUDWATCH_OPTS --dimensions InstanceId=$instanceid"