Skip to content

Latest commit

 

History

History
107 lines (84 loc) · 4.93 KB

README.md

File metadata and controls

107 lines (84 loc) · 4.93 KB

aws-apm

This app was used during the demo for the ARC315 session on re:Invent at 11/29/2017.

Here is the overall architecture diagram for this demo: alt text

When you follow the installation instructions, the following will be installed on your instance:

  1. The sample app (my_app) from this git repo.
  2. Collectd with the following plugins enabled: 2.1 cloudwatch plugin. 2.2 statsd plugin.
  3. Cloudwatch Logs Agent.
  4. X-Ray Daemon.

When you run this application, it will log data into a log file, send metrics to collectd and traces to the X-Ray daemon every second.

Note: Since cloudwatch logs agent will be forwarding those logs to CloudWatch, collectd will be sending those metrics to CloudWatch and X-Ray daemon will be sending the traces to X-Ray, you will be charged for all the data you send to CloudWatch an X-Ray.

1) Requirements

This application has only been tested on the latest Amazon Linux AMI. The instance needs to have access to the internet in order to install all the packages needed and send data to CloudWatch and X-Ray.

This demo runs on a t2.micro EC2 instance.

2) Installation

Launch the stack from the template at cloudformation/cloudwatch-xray-apm-demo-cfn.yaml.

3) Running the App

To run the app:

cd ~/aws-apm
bundle exec samples/apps/my_app.rb

You can stop it by typing Ctrl+C.

To run it on the background:

cd ~/aws-apm
nohup bundle exec samples/apps/my_app.rb &

You can stop it by running pkill -f my_app.rb.

3.1) Checking that the app is running

Check the appliation's log:

tail -100f ~/aws-apm/logs/my_app.log

3.2) Checking that collectd is sending metrics to CloudWatch

Check collectd logs:

tail -100f /var/log/collectd.log

3.3) Checking that the cloudwatch logs agant is log entries to CloudWatch

Check the cloudwatch logs agent log:

tail -100f /var/log/awslogs.log

3.4) Checking that the xray daemon is sending traces to X-Ray

Check the xray daemon logs:

tail -100f /var/log/xray/xray.log

4. UDP vs Logging Lattency Script

This script demonstrates how much lattency logging can introduce in your apps compared to sending metrics via UDP. The script will log n lines and also send n0 metrics to collectd via UDP.

Note: n is one of the input parameters you can send to the script. The first parameter is the udp port to send the metrics to (collectd listens on port 8125), the second one is the number of lines to log and udp packages to send.

For example, to log 1,000,000 lines and send 1,000,000 metrics via udp:

cd ~
bundle exec samples/latency/latency.rb 8125 1_000_000

At the end, you will see a report like this:

Logging 1000000 lines ...
Sending 1000000 messages via UDP to localhost on port 8125 ...

-------------------------------------------------------------------------
|     task     |     total time (sec)     | Throughput (operations/sec) |
-------------------------------------------------------------------------
     log               14.162302              70609.989817            
     udp               8.078506              123785.264256   

Note: You can check the logged lines at ~/aws-apm/logs/lattency_test.log. The udp packages will not be sent to CloudWatch because they are not whitelisted.

5.References

  1. CloudWatch custom metrics
    1. Collectd
    2. Statsd - hisory and source code
    3. Collectd statsd plugin
    4. Collectd cloudwatch plugin - blog post and source code
  2. CloudWatch Logs
    1. CloudWatch Logs Agent reference docs and quick start guide
    2. CloudWatch Logs Subscriptions
    3. Centralized Logging Solution on AWS
  3. AWS X-Ray
    1. segment documents
    2. Getting Started
    3. SDKs