aws-samples/aws-xray-cloudwatch-event

Name: aws-xray-cloudwatch-event

Owner: AWS Samples

Description: Sample using Amazon CloudWatch Events and Alarms to notify AWS X-Ray users when their services have elevated levels of latency, errors and faults.

Created: 2017-11-12 20:09:01.0

Updated: 2017-12-19 19:00:06.0

Pushed: 2017-12-08 05:00:11.0

Homepage: null

Size: 179

Language: Python

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Notification & Alarms for AWS X-Ray using Amazon CloudWatch

License

This sample application is licensed under the Apache 2.0 License.

Before you begin
  1. You will need an active AWS account to proceed. Create one at https://aws.amazon.com/ .
  2. Permission to run AWS CloudFormation template that will create Amazon S3 buckets, AWS Lambda functions, Amazon CloudWatch events, CloudWatch rules and AWS IAM Roles. To learn more about CloudFormation, see https://aws.amazon.com/cloudformation/.
  3. You will need Python to deploy the CloudFormation template and run the sample app. You can download and install Python from https://www.python.org/.
  4. To generate alerts and notifications, you will need an application that is instrumented and sending data to X-Ray. To get started with AWS X-Ray please visit: https://aws.amazon.com/xray/
Overview

This sample app will help you setup SMS and email alerts when services in your application have elevated latency, or error and fault rates.

Alt text

Information on pricing

This sample app uses AWS X-Ray, Amazon CloudWatch, AWS Lambda and Amazon SNS. You will be charged based on pricing for each of these individual services. Please refer to the overview section above to understand the architecture of this app and the resources it'll create. The pricing information for the services used in this application is as follows:

AWS X-Ray: https://aws.amazon.com/xray/pricing/ Amazon CloudWatch: https://aws.amazon.com/cloudwatch/pricing/ AWS Lambda: https://aws.amazon.com/lambda/pricing/ Amazon SNS: https://aws.amazon.com/sns/pricing/

Getting started
a. Information for notification

The sample app requires the following information to successfully notify you. Please note that your AWS account will be charged by Amazon SNS for these notifications beyond the free tier. For Amazon SNS pricing information please visit: https://aws.amazon.com/sns/pricing/

  1. You can configure notifications as follows:
    
    rts":
    
    "default":
    {
        "responseunitthreshold":<type: integer. Value representing minutes>,
        "errorpercentagethreshold":<type: float. Value between 0 and 1>,
        "faultpercentagethreshold":<type: float. Value between 0 and 1>,
        "throttlepercentagethreshold":<type: float. Value between 0 and 1>
    }
    
    lyzeservicemapminutes":<type: integer. The schedule (in minutes) that determines when CloudWatch Events triggers the Lambda function and time duration for analyzing the X-Ray service map>,
    luationperiodforcwalarm":<type: integer. The evaluation period for your CloudWatch alarm>,
    munications":
    
    "sms":
    [
        "type:Phone number (without dashes) with country and area code. Format: 19876543210",
        "type:Phone number (without dashes) with country and area code. Format: 19876543210"
    ],
    "email":
    [
        "type: email. Format: abcd@efgh.com",
        "type: email. Format: abcd@efgh.com"
    ]
    
    

}

optional) If you would like to only get notified for specific services in your application, you can add individual service sections:

“alerts”:

{
    <service_name_1>":
    {
        "responseminutesthreshold":<type: integer. Value representing minutes>,
        "errorpercentagethreshold":<type: float. Value between 0 and 1>,
        "faultpercentagethreshold":<type: float. Value between 0 and 1>,
        "throttlepercentagethreshold":<type: float. Value between 0 and 1>,
        "type":<type: string. The type of the node that is shown in your X-Ray service map console>
    },
    <service_name_2>":
    {
        "responseminutesthreshold":<type: integer. Value representing minutes>,
        "errorpercentagethreshold":<type: float. Value between 0 and 1>,
        "faultpercentagethreshold":<type: float. Value between 0 and 1>,
        "throttlepercentagethreshold":<type: float. Value between 0 and 1>,
        "type":<type: string. The type of the node that is shown in your X-Ray service map console>
    }
}
b. Install the sample app
CloudFormation template will create the required resources such as S3 buckets, CloudWatch events, CloudWatch rules, IAM roles and Lambda function. Note: You have to update xraycloudwatchevent.json as described above prior to installing the sample app.

it clone this repository.
o to Setup/ directory.

cd Setup/

un install.py script

python install.py

rovide your sample app name and region when requested by the install.py script.


c. Uninstall the sample app
stalling the sample app is easy as well. It removes any relevant S3 bucket and resources created by CloudFormation for this app.

o to Setup/ directory.

cd Setup/

un uninstall.py script

python uninstall.py

rovide your sample app name and region when requested by the uninstall.py script.

sing the sample app
he sample app is an AWS Lambda function, which is triggered by a CloudWatch event at the scheduled time defined by you.
his sample app analyzes your AWS X-Ray service graph, aggregated at the provided time window and sends out a CloudWatch event in case the latency, error or fault rates breach the threshold. You can define a custom threshold using the xraycloudwatch.json file.
n matching the pattern defined in the CloudWatch Rule, the CloudWatch Event will invoke the SNS topic to send a SMS message to the provided phone number.
he CloudWatch Alarm will be trigerred if TriggeredRules > 0 in the evaluation period, which is also defined in the xraycloudwatch.json file, to invoke another SNS topic that sends out an email.

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.