Skip to content

chiradeep/idle-instance

Repository files navigation

idle-instance

Terminate idle instances on cloudstack using AWS Image of Alarm Architecture

##Pre-requisites

  1. CloudStack cloud
  2. AWS CLI and AWS account API keys
  3. cloudmonkey (pip install cloudmonkey) and boto3 (pip install boto3) on the MS
  4. boto3, psutil on each cloudstack instance

##Usage

  1. Create Alarm Topic in SNS, SQS and API keys for Queue/SNS user
$ ./create-sqs-sns.sh <stack-name> <password for new IAM user to create>
E.g.,
$ ./create-sqs-sns.sh idleinstancestack l@mep@assword
  1. Grab the outputs of the stack after it is created
$ ./outputs.sh idleinstancestack
"OutputKey": "IdleInstanceAlarmSNSTopicTopicARN", 
   "OutputValue": "arn:aws:sns:us-west-2:987605588178:idleinstancestack0-IdleInstanceAlarmSNSTopic-BKKKKKKKKKKK"
"OutputKey": "IdleInstanceQueueInfo", 
   "OutputValue": "ARN: arn:aws:sqs:us-west-2:388888888888:idleinstancestack0-IdleInstanceQueue-KJJJJJJJJ URL: https://sqs.us-west-2.amazonaws.com/333333333333/idleinstancestack0-IdleInstanceQueue-KKKKKKKKKK"
"OutputKey": "IdleInstanceQueueUserInfo", 
   "OutputValue": "ARN: arn:aws:iam::384845588177:user/idleinstancestack0-IdleInstanceQueueUser-1FBJ8C0SOTGPR Access Key: AKIAABCDEDFHJKCIQNAD Secret Key: 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"
  1. Every time a VM is created, grab its UUID (say off of the event queue) and create an idle instance alarm.
$ ./create-alarm.sh <IdleInstanceAlarmSNSTopicTopicARN from output> <vm uuid>
  1. Inside each VM use the cpu.py script to sent CloudWatch metrics (customize the AWS region) every few minutes
  2. On the MS, run a job with sqs.py to fetch and delete the idle VM uuids.

About

Terminate idle instances on cloudstack using AWS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published