Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lambdas to handle cloudwatch alarms #2222

Merged
merged 8 commits into from
Oct 18, 2019

Conversation

JustinPihony
Copy link
Collaborator

@JustinPihony JustinPihony commented Oct 14, 2019

Closes #2117


This change is Reviewable

@JustinPihony
Copy link
Collaborator Author

Note that the 3 lambda_function.py are the real code to review. The rest is needed to import requests in the python lambda. We could zip it up and add a note how to deploy if it would be easier, though. Or even how to upgrade

@JustinPihony
Copy link
Collaborator Author

Once a timeline to trigger an alarm is determined, the only thing that needs done is some code cleanup and to set the schedules for the cleanup and creation lambdas to trigger. Probably ok to run once every hour? In testing they run in < 15 seconds.

@JustinPihony JustinPihony marked this pull request as ready for review October 15, 2019 03:36
@JustinPihony
Copy link
Collaborator Author

JustinPihony commented Oct 15, 2019

OK, this is ready for review/install. Current status:

  • cloudwatchAllInstances will iterate through all running instances in a region, turn on monitoring if not already, add a cpu idle watch to go off after 6 hours of idle, and check if the instance has been running for 5 or more days (re-notifying every 5th day thereafter)
  • idleNotifier is the lambda that talks to Slack. The app I created talks to #ec2-idle-notification
  • cleanOrphanCloudWatch is the lambda to search for all cloudwatch alarms which were generated by cloudwatchAllInstances (naming convention), but the instance is no longer running. I figure even if they are only stopped, then a new alarm will be added if they re-start.

I'm planning on setting up a cloudwatch rule to trigger every 30 minutes to run cloudWatchAllInstances and cleanOrphanCloudWatch. They are fairly light weight, so shouldn't be much burden, as well as make sure to notify/cleanup sooner than later. Additionally, I will have the lambdas check us-east-1, us-east-2, us-west-1, and us-west-2 (any others?).

If any of that sounds off then let me know and I can tweak. Otherwise I'll install into us-east-2 once approved - since that is where all other lambdas live.

Oh, and should we @here to get more attention to that channel, or we'll know it is important? It shouldn't be as chatty as the other automated channels

@REASY
Copy link
Collaborator

REASY commented Oct 15, 2019

@JustinPihony so many files, is it expected? There is no way to bring dependencies via pip?

@JustinPihony
Copy link
Collaborator Author

JustinPihony commented Oct 15, 2019 via email

@REASY
Copy link
Collaborator

REASY commented Oct 15, 2019

@JustinPihony you're right. Now I know that people even upload the whole binary executable. I've learned something new today :D

@wrashid
Copy link
Collaborator

wrashid commented Oct 15, 2019

I am assuming we are filtering out small instances?

@JustinPihony
Copy link
Collaborator Author

JustinPihony commented Oct 15, 2019 via email

@wrashid
Copy link
Collaborator

wrashid commented Oct 16, 2019

ok, need to be able to at least exclude specific machines which need to be running all the time

@JustinPihony
Copy link
Collaborator Author

@wrashid Fixed via 455bc48

@JustinPihony
Copy link
Collaborator Author

For some reason not all instances are being picked up in us-east-2. I had only tested for one instance, so maybe it is not properly iterating through all instances. I'll debug tonight, see what's going on and update accordingly.

@JustinPihony
Copy link
Collaborator Author

test!

@JustinPihony JustinPihony merged commit 53a9f96 into develop Oct 18, 2019
@JustinPihony JustinPihony deleted the jp/#2117-cloud-watch-idle-monitors branch October 18, 2019 03:57
@JustinPihony JustinPihony restored the jp/#2117-cloud-watch-idle-monitors branch April 23, 2020 04:46
@JustinPihony JustinPihony deleted the jp/#2117-cloud-watch-idle-monitors branch May 7, 2020 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

create cloud watch for detecting idle machines
3 participants