• Stars
    star
    126
  • Rank 282,938 (Top 6 %)
  • Language
    Python
  • License
    BSD 2-Clause "Sim...
  • Created over 8 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

AWS Hosted Uptime Monitoring

CloudPing - AWS Hosted Uptime Monitoring

https://travis-ci.org/mlavin/cloudping.svg?branch=master https://codecov.io/github/mlavin/cloudping/coverage.svg?branch=master

Overview

This project is an experiment in using AWS Lambda + CloudWatch for a nearly-free website uptime alert service. Similar to a basic Pingdom account, this fetches configured webpages and sends configurable alerts when they are down. It's slightly complicated to set up but runs almost entirely within the AWS free tier supporting multiple sites with configurable notifications.

Getting Started

To get started running your own monitoring service you'll need a clone of repository, Python 2.7, and the latest virtualenv installed:

$ git clone https://github.com/mlavin/cloudping.git
$ cd cloudping
$ make bundle

This will create a cloudping.zip file containing the cloudping.py handler script and all of its dependencies.

Configuring AWS Services

This bundled script will run in an AWS account. If you don't already have one then you should create one and continue using an administrative user for that account.

Lambda

The bundled cloudping.zip is used to run an AWS Lambda script. This should be uploaded using the AWS console selecting the following options:

  • Name: CloudPing
  • Description: Monitor webpages using Lambda
  • Runtime: Python2.7
  • Upload Zip: cloundping.zip
  • Handler: cloudping.ping
  • Role: Basic Execution Role
  • Memory: 128 MB
  • Timeout: 10 secs

CloudWatch

CloudWatch is used to run the script periodically and monitor its results. To run the script periodically you need to create a new Rule:

  • Event Selector: Schedule every 5 mins
  • Target
    • Lambda Function: CloudPing
    • Configure Input (Constant JSON text): {"domain": "example.com", "protocol": "http"}
  • Name: example_com-ping
  • Description: Ping the example.com domain periodically
  • State: Enabled

You can adjust the schedule to fit the granularity of the checks that you would like. Here the example.com references would be replaced with the domain that you wish to monitor. The input JSON can take the following options:

  • domain (default: example.com)
  • protocol (default: http)
  • path (default: /)
  • method (default: GET)
  • allow_redirects (default: False)
  • timeout (default: 5)

domain, protocol, path, and method determine what page is requested and how. allow_redirects determines whether 30X response is considered and error or if the redirect should be followed to the final page to determine the status. timeout is the timeout of the request in seconds.

The final piece is to setup an alarm which watches for errors when running the script. For this you need a new CloudWatch Alarm:

  • Metric: CloudPing Errors
  • Threshold:
    • Name: SiteDown
    • Description: Too many site errors in the window.
    • Whenever: Errors is >= 2 for 1 consecutive period
    • Period: 15 mins
    • Statistic: Sum

As with the rate of the checks, you can adjust these thresholds to fit your own needs. You can also configure the actions to send emails or SMS when the state reaches ALARM or take other actions as needed.

Cost Estimation

This makes use of 3 main AWS services which have the potential to incur costs to your AWS account: Lambda, CloudWatch, and SNS. Each has some level of free usage.

Lambda

https://aws.amazon.com/lambda/pricing/

  • The Lambda free tier includes 1M free requests per month and 400,000 GB-seconds of compute time per month.

With 128 MB of memory allocated to the Lambda function that translates to a 1,000,000 checks or 3,200,000 seconds of compute time. If each check takes less than 3 seconds then you can use the full million calls. That's enough to check ~23 pages once every minute assuming ~43,200 (60 x 24 x 30) minutes in a month.

CloudWatch

https://aws.amazon.com/cloudwatch/pricing/

  • New and existing customers also receive 3 dashboards of up to 50 metrics each per month at no additional charge.
  • New and existing customers also receive 10 metrics (applicable to Detailed Monitoring for Amazon EC2 instances, Custom Metrics, or CloudWatch Logs*), 10 alarms, and 1 million API requests each month at no additional charge.
  • New and existing customers also receive 5 GB of data ingestion and 5 GB of archived storage per month at no additional charge.

Each domain that you want to check requires firing a periodic event which is charged at $1.00/1M. If you were to max out the free Lambda calls with 1M checks in a month this would cost you $1. Each domain requires an alarm, the first 10 of which are free.

SNS

http://aws.amazon.com/sns/pricing/

  • First 1 million Amazon SNS requests per month are free
  • Free deliveries
    • Mobile Push Notifications: 1 million
    • SMS: 100
    • Email: 1,000
    • HTTP(s): 100,000

If you choose to have notifications on changes to the alarm state then you can be charged for the delivery of those notifications. If you are only notified when the site is down and it doesn't go down every day then you should have enough for SMS or email to be free each month.

Total Cost

Overall, the usage for a single site checked every 5 mins should be free. Checking every 5 mins requires ~8,640 CloudWatch events which cost $1 per million. Assuming that it doesn't generate multiple emails/SMS alerts on every check those should stay under the monthly limits or cost you $0.01/month with rounding up.

You should refer to the AWS documentation to see the most up to date usage tiers and pricing.

License

This is free software distributed under the included BSD license. You are free to copy, modify, and redistribute under the terms listed there. Please note that this is provide "as-is" without warranty. You are responsible for any changes that using this software might generate on your AWS account.

More Repositories

1

django-selectable

Tools and widgets for using/creating auto-complete selection widgets using Django and jQuery UI.
JavaScript
128
star
2

django-all-access

django-all-access is a reusable application for user registration and authentication from OAuth 1.0 and OAuth 2.0 providers such as Twitter and Facebook.
Python
59
star
3

django-responsive

Utilities for building responsive websites in Django.
Python
57
star
4

django-app-template

A handy template for creating a new reusable Django application.
Python
51
star
5

sickmuse

Sick Muse is an open source web application for graphing Collectd RRD data.
Python
30
star
6

argyle

A collection of Fabric utilities largely for Django deployment.
Python
29
star
7

django-ad-code

django-ad-code is a reusable application for managing and rendering ad tags from third-party ad server or ad network such Adsense, DoubleClick or OpenX.
Python
28
star
8

fileapi

Example project using Django and Backbone.
JavaScript
22
star
9

dotfiles

Collection of configuration files
Shell
16
star
10

django-hilbert

This is one of many Django apps which is a loose collection of utility functions.
Python
15
star
11

secretcards

Adorably secure messages
JavaScript
7
star
12

django-lastfm-auth

An extension to Django-Social-Auth which adds a backend for Last.fm
Python
7
star
13

dokku-playbooks

Ansible playbooks for managing a Dokku-Alt server
6
star
14

video-examples

Example source code for the "Intermediate Django" video tutorial series
Python
6
star
15

aiodjango

Experiment Mixing Django with aiohttp
Python
5
star
16

shoestring

Erlang WebRTC Signalling Server
Erlang
5
star
17

sanity-talk

My talk on open source project maintenance from a Django perspective
JavaScript
4
star
18

django-meetup-auth

An extension to django-social-auth which adds a backend for Meetup.com
Python
3
star
19

lecture-notes

Lecture notes for Python guest lectures
Jupyter Notebook
2
star
20

decklist

Pokemon TCG deck pricing app hosted on professordogwood.com
HTML
1
star
21

django-qjoin

Declarative Joins for the Django ORM
Python
1
star
22

hubot-image

Docker image for running Hubot
Makefile
1
star
23

mini-template

Project template for Django aimed at small webservices. 12-factor inspired configuration. To start a project with this use `$ django-admin.py startproject --template=https://github.com/mlavin/mini-template/zipball/master --extension=py,rst,txt <project_name>`
Python
1
star
24

tincan

WebRTC based file sharing
Python
1
star