This might be your first AWS Beanstalk App you ever deployed.
80 | The code base of this application was taken from the AWS Elastic Beanstalk Tutorial but was slightly modified for the Dynatrace AWS Tutorial that you can find here!
81 | The goal of this tutorial is to enable Full Stack Monitoring with Dynatrace on your Beanstalk Application. Following is a screenshot of Dynatrace Smartcape in case you deploy this application in a scalability group:
82 | If you want to learn more about Dynatrace visit our website and get started with your own Dynatrace SaaS Trial!
83 |
84 | This page is served from HOSTNAME!
85 |
86 |
87 |
88 |
Lets trace some code!
89 |
90 | Sleep Setting (in ms):
91 |
92 |
93 |
94 | Say Something :
95 |
96 |
97 |
98 |
99 | Invoke Server Side URL (full URL please) :
100 |
101 |
102 |
103 |
104 | Your Username (can be used for user tagging) :
105 |
106 |
129 |
130 |
176 |
177 |
178 |
--------------------------------------------------------------------------------
/NodeJSBeanStalkSample/launch.bat:
--------------------------------------------------------------------------------
1 | set DT_TAGS=Env=AWS Service=BeanStalkSample
2 | node app.js
--------------------------------------------------------------------------------
/NodeJSBeanStalkSample/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Elastic-Beanstalk-Sample-App",
3 | "version": "0.0.1",
4 | "private": true,
5 | "dependencies": {},
6 | "scripts": {
7 | "start": "node app.js"
8 | }
9 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AWS Monitoring Tutorials for Dynatrace SaaS/Managed
2 |
3 | WATCH THIS TUTORIAL on the [Dynatrace YouTube Channel](https://www.youtube.com/watch?v=R0bnDkM8k_o&t=124s&index=3&list=PLqt2rd0eew1YFx9m8dBFSiGYSBcDuWG38)
4 |
5 | In this tutorial we have different labs where we learn different use cases on how to monitor applications and services on AWS with Dynatrace SaaS. The same will also work if you have Dynatrace Managed installed On-Premise. Also remember: Dynatrace can not only monitor your AWS Environments but all your Apps deployed on premise, Azure, OpenStack, OpenShift, VMWare or anywhere else!
6 |
7 | 1. [Lab 1: Setting up AWS Monitoring through Cloud Watch Integration](#lab-1-setup-dynatrace-aws-monitoring-integration)
8 | 2. [Lab 2: Monitoring EC2 Instances with Dynatrace OneAgent](#lab-2-install-oneagent-on-ec2-instance)
9 | * [Lab 2(a): Monitoring EC2 instance with inbuilt application](#lab-2a-launch-an-ec2-instance-dynatraceoneagent-and-docker-application)
10 | 3. [Lab 3: Monitoring Node.JS deployed through AWS Beanstalk](#lab-3-monitor-nodejs-beanstalk-application)
11 | 4. [Lab 4: Monitoring LAMP Stack configured through CloudFormation](#lab-4-monitor-lamp-stack-configured-through-cloudformation)
12 | 5. [Lab 5: AWS ECS Container Monitoring](#lab-5-aws-ecs-container-monitoring)
13 | 6. [Lab 6: AWS CodeDeploy - Blue / Green Deployment](#lab-6-aws-codedeploy---blue--green-deployment)
14 | 7. [Lab 7: AWS Lambda Zombie Workshop with Manual RUM Injection](#lab-7-aws-lambda-zombie-workshop)
15 | 8. [Lab 8: Monitoring AWS Lambda Functions](#lab-8-monitoring-aws-lambda-functions)
16 |
17 | ## Pre-Requisits
18 | 1. You need an AWS account. If you dont have one [get one here](https://aws.amazon.com/)
19 | 2. You need a Dynatrace Account. Get your [Free SaaS Trial here!](http://bit.ly/dtsaastrial)
20 |
21 | ## Preparation
22 | **Amazon**
23 | 1. To remote into EC2 Instances we will need a Key Pair. Create one in preparation or once you walk through the lab
24 | 2. To learn more about Key Pairs and how to connect to EC2 Instances read [Connect to your Linux Instance](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstances.html)
25 |
26 | **Dynatrace OneAgent Download Instructions**
27 | 1. In your Dynatrace SaaS or Managed Portal navigate to Deploy Dynatrace -> Start Installation -> Linux
28 | 2. Copy the OneAgent Download and Installation command line (circled in red) as we will need it throughout the labs
29 | 
30 |
31 | # Lab 1 Setup Dynatrace AWS Monitoring Integration
32 | This lab will teach us how to setup the Dynatrace AWS Monitoring Integration with AWS CloudWatch.
33 | The goal is to see the Dynatrace AWS Monitoring Dashboard populuated with data pulled from both [AWS CloudWatch](https://aws.amazon.com/cloudwatch/) as well as from installed OneAgents:
34 | 
35 |
36 | **Step-by-Step Guide**
37 | 1. For Dynatrace SaaS please open [Dynatrace Doc: How do I start Amazon Web Service Monitoring](https://www.dynatrace.com/support/help/cloud-platforms/amazon-web-services/how-do-i-start-amazon-web-services-monitoring/). For Dynatrace Managed check out [Dynatrace Doc: How do I monitor AWS using role-based access?](https://help.dynatrace.com/dynatrace-managed/dynatrace-server/how-do-i-monitor-aws-using-role-based-access/)
38 | 2. Follow the instructions for either Role or Key-based authentication
39 | 3. Tip for Role-based: Make sure you remember the Role Name, your AWS Account ID and the External ID while creating the role. You will need it at the very last step of the configuration
40 | 4. Tip for Key-based authentication: For quick evaluation I think this is the easiest path assuming your AWS User has the [required policies attached](https://www.dynatrace.com/support/help/shortlink/aws-saas-deployment#monitoring-policy).
41 | 4. Once done Validate that Dynatrace shows data in the AWS Dashboard. Simply click on "AWS" in the Dynatrace menu and you should see a simliar screen as shown above
42 |
43 | **Costs:** AWS charges for CloudWatch API access when exceeding 1 million requests. More details can be found in the Dynatrace and CloudWatch Documentation
44 |
45 | # Lab 2 Install OneAgent On EC2 Instance
46 | This lab will teach us how to install a Dynatrace OneAgent on a Linux EC2 Instance.
47 | The goal is that the EC2 host will show up in Dynatrace and is fully monitored through a OneAgent
48 | 
49 |
50 | There are multiple ways to install a Dynatrace OneAgent on a "bare" EC2 Instance. If configuration management tools such as Puppet, Chef, Ansible or AWS CodeDeploy are used then Dynatrace OneAgent deployment can be done through these tools.
51 | Another very convenient approach for EC2 is to specify startup scripts that automatically get executed whenever Amazon launches an EC2 instances. In EC2 this is called "User Data".
52 |
53 | **Step-by-Step Guide**
54 | 1. Logon to AWS and navigate to EC2. [This link](https://us-east-2.console.aws.amazon.com/ec2/v2/home) should also get you there!
55 | 2. Now select the option to **Launch a new Instance**
56 | 3. Select **Amazon Linux AMI** and then select the free tier eligible **t2.micro** instance type. Select Next
57 | 4. **Configure Instance:** Expand the Advanced section and specify the following User Data script (make sure you use your unique OneAgent Download URI or simply use the full two script lines that you see in the Dynatrace Deploy Agent Web UI)
58 | ```
59 | #!/bin/bash
60 | wget -O Dynatrace-OneAgent-Linux.sh https://YOUR.FULL.DYNATRACE.ONEAGENT.DOWNLOADLINK
61 | /bin/sh Dynatrace-OneAgent-Linux.sh APP_LOG_CONTENT_ACCESS=1
62 | ```
63 | 5. Click next and make yourself familiar with Storage options. We keep the defaults
64 | 6. **Add Tags:** on this configuration screen we add a custom tag. Key=EC2InstanceType; Value=LabExcercise.
65 | 7. Click through the rest of the steps. Review settings and click Launch
66 | 8. **Select or create** a new key pair. We will need this for remoting into EC2
67 | 9. You can observe the launch log
68 | 10. Navigate to the Dynatrace Hosts list and wait until the host shows up. Click on it and explore what is monitored
69 | 11. Expand the list of Properties and Tags. We should also find our EC2InstanceType tag with the value LabExcercise
70 |
71 | **Troubleshooting:**
72 | If something doesnt go as expected what to do? Well - Amazon provides a good way to access these EC2 instances
73 | 1. Navigate to your [EC2 Manager Console](https://us-east-2.console.aws.amazon.com/ec2/v2/home)
74 | 2. Select the EC2 instance in question
75 | 3. Explore the options such as **Connect** and follow the instructions to remote into that machine.
76 | 4. Explore **Actions -> Instance Settings -> Get System Log** to get access to the system log and verify what happened during startup
77 | 
78 |
79 | **Useful Links**
80 | * [Running commands on your Linux Instance during Startup](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html)
81 | * [Running commands on your Windows Instance during Startup](http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/UsingConfig_WinAMI.html#user-data-execution)
82 |
83 | # Lab 2a Launch an Ec2 Instance DynatraceOneAgent and docker application
84 | In this step we will Launch an EC2 instance with an inbuilt Docker application, install Dynatrace OneAgent and access the Dynatrace Web UI to view our instance being monitored.
85 |
86 | **Step by Step Guide**
87 | 1. Log into to AWS console
88 | 2. Select EC2 and Click on Launch an Instance. Make sure you are launching the EC2 instance in Oregon region (Top right menu)
89 | 3. Click on Community AMI's. In the Search box type dynatrace. Select the image **Dynatrace_Easytravel_Docker_EC2**
90 |
91 | 
92 |
93 | 4. Select **t2.medium** instance type and Click on **Configure Instance Details**
94 | 5. Expand the Advanced Details and specify the following User Data script (Grab the unique URL for Dynatrace OneAgent install from your Dynatrace UI)
95 |
96 | ```
97 | #!/bin/sh
98 | wget
99 | /bin/sh
100 | chown ec2-user:ec2-user /home/ec2-user/easyTravel-Docker/docker-compose.yml
101 | /usr/local/bin/docker-compose -f /home/ec2-user/easyTravel-Docker/docker-compose.yml up -d
102 | ```
103 | 6. Click Next, explore the options and Launch the EC2 instance. (You will have to generate or use an already existing Key to remote into the EC2 instance)
104 | 7. Now we will look into the Dynatrace UI to see monitoring data
105 |
106 |
107 | # Lab 3 Monitor-NodeJS-Beanstalk-Application
108 | This lab will teach us how to install a Dynatrace OneAgent into a Node.js application deployed with AWS Beanstalk.
109 | As a base we use the sample node.js application that AWS uses in their tutorials. For more information see ...
110 | The goal of this lab is to have full Node.js and End User monitoring enabled with Dynatrace.
111 |
112 | **Background Information on Beanstalk**
113 |
114 | Beanstalk allows you to simply upload your application code as a zip or war file to AWS. AWS Beanstalk then
115 | 1. Launches a new EC2 instance for you with the required runtime (Node.js, PHP, Java, .NET ...)
116 | 2. Extracts your ZIP/WAR file onto that machine
117 | 3. Sets Environment Variables and executes startup scripts to prepare the environment#
118 | 4. Launches the runtime environment (Node.js, PHP, Java, .NET ...)
119 |
120 | *Installing OneAgent on Beanstalk*
121 | One way to install a Dynatrace OneAgent on such a Beantstalk EC2 instance is to leverage the "Elastic Beanstalk Extensions" concept. Beanstalk allows you to put additonal configuraton and script instructions into a subfolder called .ebextensions. Files with the ending .config will then be analyzed and executed during the startup phase of an instance. In our example you will find the following files in the .ebextension directory:
122 | * dynatrace.config: Defines one Configuration Option (DYNATRACE_ONEAGENT_DOWNLOAD). It also comes with a special beanstalk installation script that gets put into a special directory which will be executed by Beanstalk as part of the instance launch process. This script references the DYNATRACE_ONEAGENT_DOWNLOAD option. You could either set the option value in the .config file before uploading it to AWS or you can set the value later when configuring the launch parameters. We will do THE LATTER.
123 | * version.config: This config files specifies additional environment variables that are set to the EC2 instance. It can be used to demonstrate custom process group tagging with Dynatrace
124 |
125 | **Prerequisit**
126 | 1. Download the NodeJSBeanStalkSample from this GitHub Repo
127 | 2. Explore the .ebextensions directory as explained above
128 | 3. Create a ZIP file of the full NodeJSBeanStalkSample including .ebextension directory. ATTENTION MAC USERS: Please make sure to create the zip from your terminal. Otherwise you may end up with the __MACOSX subfolder which can become a problem later on
129 |
130 | **Step-by-Step-Guide**
131 | 1. Logon to AWS and Navigate to Elastic Beanstalk. [This link](https://us-east-2.console.aws.amazon.com/elasticbeanstalk/home) should also get you there
132 | 2. **Create a new application**
133 | 3. Give it a name. Select **Node.js** as the platform and **upload your zip** file. Then click on **Configure more options**
134 | 
135 | 4. Click on Software Options and add DYNATRACE_ONEAGENT_DOWNLOAD with the full download URL for your OneAgent. Click on Save
136 | 
137 | 5. Now its time to launch the environment
138 | 6. Once the environment is up and running we can access the website. It is a very simply one page website that is delivered by Node.js. Dynatrace OneAgent will automatically inject the JavaScript Tag for Real User Monitoring. You can verify that.
139 | 
140 |
141 | **Additional Step: Process Group Identification**
142 | Dynatrace automatically detects process groups and by default does a pretty good job in detecting the logical application deployed by looking at different environment variables or application server configuration files. If you want to override that process you can configure a custom Process Group Detection Rule. In our version.config file we specify a custom environment variable called MYVERSION. In this additional step we simply configure dynatrace to detect the Process Group Name based on that value in case this environment variable is set.
143 | 1. In Dynatrace go to Settings -> Monitoring -> Process group detection
144 | 2. Add a new rule for Node.js and specify MYVERSION as the environment variable to look at
145 | 3. Next time you launch your application you will see Dynatrace will capture that value of our MYVERSION Environment Variable
146 |
147 | **Additional Step: Load Balancing**
148 | 1. Go to your Beanstalk Environment in AWS Console
149 | 2. Click on Configuration - Scaling
150 | 3. Change the environment type to "Load balancing, auto scale"
151 | 4. Apply the changes and let Beanstalk restart
152 | 5. Go back to the same settings after restart and change auto scale to minimum instances of 2
153 | 6. Apply changes and validate that Dynatrace detects both instances
154 |
155 | **Additional Step: Real User Monitoring**
156 | There are some additional RUM configurations we can define to better leverage Dynatrace Real User Monitoring
157 | 1. Enable jQuery support for our Beanstalk Application. You can configure this through the Web Application Settings!
158 | 2. Configure Cookie Support for elasticbeanstalk.com domains: If you host your app on the default domain given by AWS you have to go into the Advanced Settings for your Application and specify your full domain name, e.g: custom-env.ub2cp9hmpy.us-west-2.elasticbeanstalk.com in the field **Domain to be used for cookie placement**. Otherwise your browser will reject the Dynatrace Cookies necessary for end user tagging. This step IS NOT necessary if you host your app on a "normal" domain!
159 | 3. [Configure User Tagging](https://www.dynatrace.com/blog/automatic-identification-users-based-page-metadata/). The Application has a login button which will then set the Username to an HTML Element with the ID #loggedinusername. Please configure User Tagging by picking up that value through CSS Selectors
160 | Now you should be able to find your user by looking for the user name and see every single interaction with any button.
161 | *REMEMBER:* User Visits right now will show up once the Visits are completed which means after the 30 minutes timeout!
162 |
163 | **Additional Step: Request Tagging**
164 | Dynatrace provides a great way to dynamically tag web requests based on information passed to each web request. In our sample app we have calls to /api/version, /api/invoke, ...
165 | 1. Go to Settings -> Server-Side -> [Request attributes](https://www.dynatrace.com/blog/request-attributes-simplify-request-searches-filtering/)
166 | 2. Configure tagging for the pattern /api/\* and for the parameter text on /api/echo?echo=
167 | Try it out and then perform web request analysis based on these tags!
168 |
169 | Here is what you should see if you go to Smartscape. Dynatrace shows the logical Node.js service. The name BeanStalkService_v1 is actually taken from our previously defined custom process group detection. We also see that this service runs on 2 Node.js instances on two different EC2 hosts in two Availability Zones:
170 | 
171 |
172 | **Useful Links**
173 | * [What Is AWS Beanstalk](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/Welcome.html)
174 | * [Dynatrace Blog:Set up custom process group monitoring](https://www.dynatrace.com/blog/set-custom-process-groups-monitoring/)
175 | * [Request Attribute Tagging](https://www.dynatrace.com/blog/request-attributes-simplify-request-searches-filtering/)
176 | * [User Tagging with Dynatrace](https://www.dynatrace.com/blog/automatic-identification-users-based-page-metadata/)
177 |
178 | # Lab 4 Monitor LAMP Stack configured through CloudFormation
179 | This lab will teach us how to use a pre-configured CloudFormation stack to configure a classical LAMP stack. We will inject the Dynatrace OneAgent into the User Data portion of the EC2 instance launch by changing the CloudFormation template. This will allow us to create multipl stacks of the same LAMP stack including Dynatrace OneAgent monitoring
180 |
181 | **Step-by-Step-Guide**
182 | 1. Logon to AWS and navigate to the [CloudFormation Service](https://us-east-2.console.aws.amazon.com/cloudformation/home)
183 | 2. **Create a new Stack**: Select LAMP Stack and then click on *View/Edit template*
184 | 
185 | 3. We are going to add one new parameter: _DynatraceOneAgentLink_ which users can later provide. Simply add the following code snipped to the parameters in the JSON Editor
186 | ```
187 | "DynatraceOneAgentLink": {
188 | "Description": "Dynatrace OneAgent Download",
189 | "Type": "String",
190 | "MaxLength": "256",
191 | "ConstraintDescription": "Full Download Link to your Dynatrace OneAgent. Get this from your Settings -> Deploy screen in your Dynatrace SaaS/Managed console"
192 | },
193 | ```
194 | 4. Now we are going to add a similar User Data startup script as we did when instrumenting a regular EC2 Instance launch. Scroll down to the "UserData" Property Definition. Right after the line "yum update -y aws-cfn-bootstrap\n" we will add the following code.:
195 | ```
196 | "# Install Dynatrace OneAgent\n",
197 | "cd /home/ec2-user\n",
198 | "wget -O Dynatrace-OneAgent-Linux.sh ",
199 | {
200 | "Ref": "DynatraceOneAgentLink"
201 | },
202 | "\n",
203 | "/bin/sh Dynatrace-OneAgent-Linux.sh APP_LOG_CONTENT_ACCESS=1\n",
204 | ```
205 | 5. **Click on "Validate Template"** in the toolbar to make sure you have no typos. **PROBLEMS??** If you dont waste too much time feel free to copy/paste the [complete template from here!](/LAMPCloudFormationSample/LAMPTemplateWITHDynatraceOneAgent)
206 | 6. Now we have a CloudFormation script that will launch a LAMP Stack but that will also install a Dynatrace OneAgent where the actual download link is configurable through _DynatraceOneAgentLink_.
207 | 7. **Click on Create Stack** in the toolbar. This will get you back to the previous screen with your new template already uploaded to S3
208 | 8. **Click on Next**
209 | 9. Now we have to fill out all the parameters - including our _DynatraceOneAgentLink_. For the Dynatrace One Agent Link make sure to copy the complete path INCLUDING the " (quotes). Please also choose a good name for the stack and provide any type of passwords for the database properties. When done **Click Next**
210 | 
211 | 10. **Options**: Here you could define additonal tags that would automatically be picked up by Dynatrace OneAgent. Feel free to define a tag and explore that option. Once done **Click Next**
212 | 11. **Review**: Review your settings - then **Click Create**
213 | 12. You will end up in the Stack List. TIP: if your Stack doesnt show up click the Refresh button! It will take a while until everything is fully created!
214 | 13. Once the environment is in status *CREATE_COMPLETE* select the entry and find the URL to your enviornment in the Output tab in the bottom. Open that URL. You will see that PHP returns its standard page.
215 | 14. **Dynatrace**: Now move over to Dynatrace and explore the data collected. If you click on Technology you should see Apache and MySQL show up. Click on Apache, expand the bottom list of process groups and click on Proces Group Details. From there you can navigate further to the actual process group and explore more about the data captured:
216 | 
217 | Navigating to the Smartscape actually shows you how Dynatrace OneAgent really automatically detects every single process on that EC2 Linux instance including MySql and some other native processes
218 | 
219 |
220 | **Optional Step: MySQL Monitoring**
221 | As the LAMP stack comes with MySQL we can easily setup [MySQL Monitoring with Dynatrace](https://www.dynatrace.com/technologies/database/mysql-monitoring/mysql-performance/).
222 | Follow these steps
223 | 1. Click on Technologies and find the MySQL tile (notice the tile is light blue which means no deep monitoring in the moment)
224 | 2. Click on the tile and navigate your way through the process groups until you end up on your MySQL Process Group.
225 | 3. Follow the instructions to enable MySQL Monitoring. You will be able to specify username and password for Dynatrace to query your MySQL Database
226 | 4. Once you are done you will see MySQL Metrics in your MySQL Process Group. Explore the _MySQL metrics_ as well as in _Further details_
227 | 
228 |
229 | **Useful Links**
230 | * [AWS CloudFormation documentation](https://aws.amazon.com/documentation/cloudformation/)
231 |
232 | # Lab 5 AWS ECS Container Monitoring
233 |
234 | If you are new to ECS and want to get a quick start I recommend walking through the sample application deployment wizard. This wizard will create
235 | 1. Your First ECS Cluster
236 | 2. A EC2 Launch Configuration
237 | 3. A Auto Scaling Group using that Launch Configuration
238 | 4. A Task that runs a sample web site in a container
239 |
240 | In order to get Dynatrace Monitoring into that wizard generated scenario I found the easiest to modify the EC2 Launch Configuration and adding the Dynatrace OneAgent Installation steps to the User Data confiugration. As AWS doesnt allow to edit an existing Launch Configuration we have to copy it, modify it and then change the Auto Scaling group to point to our new Launch Configuration.
241 | Here are the steps involved
242 | 1. Make a copy of the Wizard generated Launch Configuration
243 | 2. Edit the User Data portion and add the OneAgent Installation steps. *ATTENTION:* The default AMI that is used for ECS EC2 Container Instances doesnt come with wget but it comes with curl. I also noticed I have to execute the install script with sudo in order for the installation script to run as root. Here is the code snippet that should work:
244 | ```
245 | #!/bin/bash
246 | curl -O Dynatrace-OneAgent-Linux.sh https://YOUR.FULL.DYNATRACE.ONEAGENT.DOWNLOADLINK
247 | sudo /bin/sh Dynatrace-OneAgent-Linux.sh APP_LOG_CONTENT_ACCESS=1 INFRA_ONLY=0
248 | ```
249 | 3. Edit the Auto Scaling Group and configure it to use your new EC2 Launch Configuration
250 | 4. Terminate the current EC2 Instances that were created previously. The Auto Scaling Group will make sure to launch new ones but now using your new Launch Configuration
251 |
252 | THATS IT :-)
253 |
254 | # Lab 6 AWS CodeDeploy - Blue / Green Deployment
255 |
256 | Similar to the ECS Lab I suggest you use the wizard that will create all configuration entries to deploy an app using a Blue/Green Deployment model. And just as we did in the ECS Lab I think the best way to inject the Dynatrace OneAgent is to duplicate the EC2 Launch Configuration, add the OneAgent Installation steps and then use this new Launch Configuration for the Auto Scaling Group that the wizard also created. That should do the trick!
257 |
258 | Here is a screenshot of my User Data configuration for the edited Launch Configuration. You can see the OneAgent installation procedure I added just before the AWS CodeDeploy Agent gets installed
259 | 
260 |
261 | # Lab 7 AWS Lambda Zombie Workshop
262 | This lab from Amazon promotes Servless technology. It is often used on AWS Servless Meetups and Hackathons.
263 | Please follow the instructions on the [AWS Lambda Zombie Workshop GitHub Repo](https://github.com/awslabs/aws-lambda-zombie-workshop).
264 | For the Dynatrace lab we do not need to go through the full excercise. Just the initial deployment of the app and inintial configuration steps are sufficient to get the app up& running.
265 |
266 | Once the application is deployed you will see that Dynatrace automatically monitors those resources used by this application: DynamoDB and Lambdas (through our AWS Monitoring Integration)
267 |
268 | **Enable Real User Monitoring**
269 | In order to enable Real User Monitoring we have to manually inject the Dynatrace JavaScript Tag because the HTML pages are static files delivered through S3.
270 | Follow these steps to get this accomplished
271 | 1. Go to S3 and browse to the index.html page in the zombiestack S3 bucket
272 | 2. Download that index.html page
273 | 3. In Dynatrace setup agentless monitoring for a new Zombie App. Copy that JavaScript snippet
274 | 4. Edit the local index.html page and add the JavaScript snippet in the of the html file
275 | 5. Upload the modified index.html file
276 | From now on, every time you access the Zombie Web Application the Dynatrace JavaScript Agent will be loaded. This means that you have automatic real end user monitoring!
277 | 
278 |
279 | # Lab 8 Monitoring AWS Lambda Functions
280 |
281 | If you want to monitor your AWS Lambda functions please follow the instructions for [How do I integrate Node.js Lambda functions](https://www.dynatrace.com/support/help/cloud-platforms/amazon-web-services/how-do-i-integrate-nodejs-lambda-functions/)
282 |
283 | In case you do not yet have a Lambda function that you can monitor feel free to setup a Lambda function with a respective API Gateway configuration based on the following very simply Lambda Node.js source code
284 |
285 | ```js
286 | /**
287 | * This is a very simply lambda function that simply executes random HTTP Requests to a randomly selected group of URLs
288 | * With the Dynatrace OneAgent injected you can end-to-end trace these calls
289 | *
290 | */
291 | exports.handler = (event, context, callback) => {
292 | // TODO implement
293 | executeRequest("http://www.dynatrace.com");
294 | executeRequest("http://www.amazon.com");
295 | executeRequest("http://www.google.com");
296 | };
297 |
298 | var executeRequest = function(url, callback) {
299 | var https = require("https");
300 | var fullUrl = require("url").parse(url);
301 |
302 | var request_options = {
303 | host: fullUrl.host,
304 | path: fullUrl.path,
305 | method: 'GET',
306 | };
307 |
308 | // Set up the request
309 | var get_req = https.request(request_options, function(res) {
310 | var responseBody = "";
311 | res.setEncoding('utf8');
312 | res.on('data', function (chunk) {
313 | responseBody += chunk;
314 | });
315 | res.on('end', function() {
316 | console.log(url + ": StatusCode = " + res.statusCode + " ContentLength: " + responseBody.length);
317 | //callback(null, null);
318 | });
319 | });
320 |
321 | // post the data
322 | get_req.end();
323 |
324 | }
325 | ```
326 |
327 | To enable Dynatrace Lambda Monitoring follow instructions based on [How do I integrate Node.js Lambda functions](https://www.dynatrace.com/support/help/cloud-platforms/amazon-web-services/how-do-i-integrate-nodejs-lambda-functions/)
328 | If you have instrumented your Lambda and then execute it via the endpoint of your API Gateway you will see that Dynatrace captures PurePaths as shown below:
329 |
330 | 
331 |
332 | For more information on Lambda support (Node.js, Java, ...) please have a look at our website and blog where our team constantly announces new and updated technology support for [Lambda and other Serverless technologies](https://www.dynatrace.com/news/tag/serverless/).
333 |
--------------------------------------------------------------------------------
/TestingScripts/nodejsbeanstalktest.js:
--------------------------------------------------------------------------------
1 | var page = require('webpage').create(),
2 | system = require('system'),
3 | t, address;
4 |
5 | // ======================================================================
6 | // Usage
7 | // ======================================================================
8 | if (system.args.length === 1) {
9 | console.log('Usage: nodejsbeanstalktest.js []');
10 | phantom.exit();
11 | }
12 |
13 | // ======================================================================
14 | // Helper Functions
15 | // ======================================================================
16 | function random (low, high) {
17 | var randomResult = Math.round(Number(Math.random() * (high - low))) + low;
18 | if(randomResult > high) randomResult = high;
19 | return randomResult;
20 | }
21 |
22 | function clickOnElementById(id) {
23 | page.evaluateJavaScript("function() { var ev=document.createEvent('MouseEvent');ev.initMouseEvent('click',true,true,window, null, 0, 0, 0, 0,false,false,false,false,0,null); document.getElementById('" + id + "').dispatchEvent(ev); }");
24 | }
25 |
26 | var minWaitFor = 0;
27 | phantom.waitFor = function(callback, maxTime) {
28 | var startTime = Date.now();
29 | var timeLapsed = 0;
30 | do {
31 | // Clear the event queue while waiting.
32 | // This can be accomplished using page.sendEvent()
33 | this.page.sendEvent('mousemove');
34 | timeLapsed = (Date.now() - startTime);
35 | } while ((timeLapsed < minWaitFor) || (!callback() && (timeLapsed < maxTime)));
36 | }
37 |
38 | // ======================================================================
39 | // Prep Work - Setting up our variables
40 | // ======================================================================
41 | var randomUserNames = ["Andi","Joe","Gabi","Stephan","Joshua","John","Asad","Ted","Karolina","Jilene","Marci","Katie","Laurie","Lynne","Peter","Wayne","Joe","Ted","Susan"];
42 | var randomEchStrings = ["Just Echo", "Another Echo", "Whats up?", "Hello??", "Somebody out there?"];
43 | var randomInvokeURLs = ["https://www.amazon.com","http://www.cnn.com","http://www.foxnews.com","https://www.twitter.com","https://www.facebook.com","http://www.orf.at","http://www.dynatrace.com"];
44 | t = Date.now();
45 | address = system.args[1];
46 | var username = (system.args.length > 2) ? system.args[2] : randomUserNames[random(0, randomUserNames.length)];
47 | var echostring = (system.args.length > 3) ? system.args[3] : randomEchStrings[random(0, randomEchStrings.length)];
48 | var invokeURL = (system.args.length > 4) ? system.args[4] : randomInvokeURLs[random(0, randomInvokeURLs.length)];
49 | if(username == null || username == "undefined") username = "Default User";
50 | if(echostring == null || echostring == "undefined") echostring = "Default Echo";
51 | if(invokeURL == null || invokeURL == "undefined") invokeURL = "https://aws.amazon.com";
52 | console.log("Start URL: " + address);
53 | console.log("Username: " + username);
54 | console.log("EchoString: " + echostring);
55 | console.log("InvokeURL: " + invokeURL);
56 | phantom.cookieEnabled = true;
57 |
58 | // ======================================================================
59 | // Step Finish: Waits until the step is done and then moves to the next or stops the script execution
60 | // ======================================================================
61 | function stepFinish(nextStep) {
62 | phantom.waitFor(function() {return !page.loading;}, 3000);
63 | var currResultText = page.evaluate(function(id) {return document.getElementById(id).innerText;}, "result");
64 | console.log("Current Result Text: " + currResultText);
65 |
66 | if(nextStep != null) nextStep(); else {
67 | console.log("DONE!!");
68 | phantom.exit();
69 | }
70 | }
71 |
72 | // ======================================================================
73 | // Step 1: Load the initial page
74 | // ======================================================================
75 | function step1Open() {
76 | page.loading = true;
77 | page.onResourceRequested = function(request, networkRequest) {
78 | console.log('Request ' + JSON.stringify(request, undefined, 4));
79 | console.log('Cookies' + JSON.stringify(page.cookies, undefined, 4));
80 | };
81 | page.onResourceReceived = function(response) {
82 | // console.log('Receive ' + JSON.stringify(response, undefined, 4));
83 | };
84 | page.open(address, function(status) {
85 | if (status !== 'success') {
86 | console.log('FAIL to load the address');
87 | } else {
88 | t = Date.now() - t;
89 | console.log('Loading ' + system.args[1]);
90 | console.log('Loading time ' + t + ' msec');
91 | }
92 | page.loading = false;
93 |
94 | console.log('Cookies' + JSON.stringify(page.cookies, undefined, 4));
95 |
96 | setTimeout(stepFinish, 5000, step2Login);
97 | });
98 | }
99 |
100 | // ======================================================================
101 | // Step 2: Login
102 | // ======================================================================
103 | function step2Login() {
104 | console.log("CLICK ON LOGIN");
105 | page.evaluateJavaScript("function() { $('#Username').val('" + username + "'); }");
106 | clickOnElementById("Login");
107 |
108 | setTimeout(stepFinish, 5000, step3Echo);
109 | }
110 |
111 | // ======================================================================
112 | // Step 3: Click on Echo
113 | // ======================================================================
114 | function step3Echo() {
115 | console.log("CLICK ON ECHO");
116 | page.evaluateJavaScript("function() { $('#SayText').val('" + echostring + "'); }");
117 | clickOnElementById("Echo");
118 |
119 | setTimeout(stepFinish, 5000, step4Invoke);
120 | }
121 |
122 | // ======================================================================
123 | // Step 4: Click on Invoke
124 | // ======================================================================
125 | function step4Invoke() {
126 | console.log("CLICK ON INVOKE");
127 | page.evaluateJavaScript("function() { $('#RemoteURL').val('" + invokeURL + "'); }");
128 | clickOnElementById("Invoke");
129 |
130 | setTimeout(stepFinish, 5000, null);
131 | }
132 |
133 |
134 | // LAUNCH Script
135 | step1Open();
--------------------------------------------------------------------------------
/TestingScripts/readme.md:
--------------------------------------------------------------------------------
1 | Here you find testing scripts that can be used to generate traffic against the applications we are hosting on AWS
2 |
3 | # Node JS Beanstalk Traffic
4 | The script [nodejsbeanstalktest.js](/nodejsbeanstalktest.js) uses [PhantomJS](http://phantomjs.org/download.html) which is a free head-less browser testing software.
5 | The script has one mandatory and 3 optional parameters
6 | ```
7 | Usage: nodejsbeanstalktest http://yournodejsbeanstalkurl [username] [echostring] [invokeurl]
8 | ```
9 | The script will execute the following steps
10 | 1. Open your BeanStalk URL
11 | 2. Enters an Echo String and Clicks the Echo Button
12 | 3. Enters the Remote URL and hits Invoke Button
13 | 4. Eners the Username and hits Login
14 | The script will use your defined parameters. If they are not present the script will use a meaningful random value.
15 |
16 | ## Running consistent load from Windows
17 | The following can be used as a windows batch file to run these tests in an endless loop. Simply fill in your URL and PhantomJS location
18 | ```
19 | set PHANTOMHOME=C:\phantomjs\phantomjs-2.1.1-windows\bin
20 | set NODEJSURL=http://YOURURL.elasticbeanstalk.com/
21 |
22 | :again
23 | %PHANTOMHOME%/phantomjs nodejsbeanstalktest.js %NODEJSURL%
24 | goto again
25 | ```
26 |
27 | ## Running consistent load from Linux
28 | For linux we can do something very similar
29 | ```
30 | EXPORT PHANTOMHOME=./phantomjs-2.1.1-linux-x86_64/bin/phantomjs
31 | EXPORT NODEJSURL=http://YOURURL.elasticbeanstalk.com/
32 |
33 | while true
34 | do
35 | echo "Hit CTRL-C to stop";
36 | sleep 1;
37 | $PHANTOMHOME nodejsbeanstalktest.js $NODEJSURL
38 | done
39 | ```
40 | If you save this into a bash you can even run it in parallel and with that generate even more load!
41 |
42 | Tip for AWS:
43 | If you want to generate load from AWS I suggest to create an EC2 Linux Instance and use the following script in the User Data section:
44 | ```
45 | #!/bin/bash
46 | wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
47 | tar -xvf phantomjs-2.1.1-linux-x86_64.tar.bz2
48 | wget https://raw.githubusercontent.com/Dynatrace/AWSMonitoringTutorials/master/TestingScripts/nodejsbeanstalktest.js
49 |
50 | export PHANTOMHOME=./phantomjs-2.1.1-linux-x86_64/bin/phantomjs
51 | export NODEJSURL=http://YOURURL.elasticbeanstalk.com/
52 |
53 | while true
54 | do
55 | echo "Hit CTRL-C to stop";
56 | sleep 1;
57 | $PHANTOMHOME nodejsbeanstalktest.js $NODEJSURL
58 | done
59 | ```
60 |
--------------------------------------------------------------------------------
/TestingScripts/win_beanstalk.bat:
--------------------------------------------------------------------------------
1 | REM this script will run in an infinite loop and executes the nodejs phantom js script
2 | REM make sure to set the following environment variables: PHANTOMHOME, NODEJSURL
3 | set PHANTOMHOME=C:\phantomjs\phantomjs-2.1.1-windows\bin
4 | set NODEJSURL=http://custom-env.ub2cp9hmpy.us-west-2.elasticbeanstalk.com/
5 |
6 | :again
7 | %PHANTOMHOME%/phantomjs nodejsbeanstalktest.js %NODEJSURL%
8 | goto again
--------------------------------------------------------------------------------
/images/lab1_awsdashboard.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dynatrace/AWSMonitoringTutorials/6e3d8899fb3ece7d6673af3660ca859136c14250/images/lab1_awsdashboard.png
--------------------------------------------------------------------------------
/images/lab1_ec2instancelist.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dynatrace/AWSMonitoringTutorials/6e3d8899fb3ece7d6673af3660ca859136c14250/images/lab1_ec2instancelist.PNG
--------------------------------------------------------------------------------
/images/lab2_ec2hostmonitor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dynatrace/AWSMonitoringTutorials/6e3d8899fb3ece7d6673af3660ca859136c14250/images/lab2_ec2hostmonitor.png
--------------------------------------------------------------------------------
/images/lab2a_ec2imageselection.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dynatrace/AWSMonitoringTutorials/6e3d8899fb3ece7d6673af3660ca859136c14250/images/lab2a_ec2imageselection.PNG
--------------------------------------------------------------------------------
/images/lab2a_userdatascript.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dynatrace/AWSMonitoringTutorials/6e3d8899fb3ece7d6673af3660ca859136c14250/images/lab2a_userdatascript.PNG
--------------------------------------------------------------------------------
/images/lab3_beanstalkec2instance.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dynatrace/AWSMonitoringTutorials/6e3d8899fb3ece7d6673af3660ca859136c14250/images/lab3_beanstalkec2instance.png
--------------------------------------------------------------------------------
/images/lab3_beanstalkloadbalanced.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dynatrace/AWSMonitoringTutorials/6e3d8899fb3ece7d6673af3660ca859136c14250/images/lab3_beanstalkloadbalanced.png
--------------------------------------------------------------------------------
/images/lab3_createnodeapp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dynatrace/AWSMonitoringTutorials/6e3d8899fb3ece7d6673af3660ca859136c14250/images/lab3_createnodeapp.png
--------------------------------------------------------------------------------
/images/lab3_softwareenv.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dynatrace/AWSMonitoringTutorials/6e3d8899fb3ece7d6673af3660ca859136c14250/images/lab3_softwareenv.PNG
--------------------------------------------------------------------------------
/images/lab4_apacheprocessgroup.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dynatrace/AWSMonitoringTutorials/6e3d8899fb3ece7d6673af3660ca859136c14250/images/lab4_apacheprocessgroup.png
--------------------------------------------------------------------------------
/images/lab4_configurestack.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dynatrace/AWSMonitoringTutorials/6e3d8899fb3ece7d6673af3660ca859136c14250/images/lab4_configurestack.png
--------------------------------------------------------------------------------
/images/lab4_createlampstack.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dynatrace/AWSMonitoringTutorials/6e3d8899fb3ece7d6673af3660ca859136c14250/images/lab4_createlampstack.png
--------------------------------------------------------------------------------
/images/lab4_lampsmartscape.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dynatrace/AWSMonitoringTutorials/6e3d8899fb3ece7d6673af3660ca859136c14250/images/lab4_lampsmartscape.png
--------------------------------------------------------------------------------
/images/lab4_mysql.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dynatrace/AWSMonitoringTutorials/6e3d8899fb3ece7d6673af3660ca859136c14250/images/lab4_mysql.png
--------------------------------------------------------------------------------
/images/lab5_endusermonitoring.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dynatrace/AWSMonitoringTutorials/6e3d8899fb3ece7d6673af3660ca859136c14250/images/lab5_endusermonitoring.png
--------------------------------------------------------------------------------
/images/lab6_bluegreen_launchconfiguration_userdata.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dynatrace/AWSMonitoringTutorials/6e3d8899fb3ece7d6673af3660ca859136c14250/images/lab6_bluegreen_launchconfiguration_userdata.png
--------------------------------------------------------------------------------
/images/lab8_LambdaFunctionPurePath.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dynatrace/AWSMonitoringTutorials/6e3d8899fb3ece7d6673af3660ca859136c14250/images/lab8_LambdaFunctionPurePath.PNG
--------------------------------------------------------------------------------
/images/lab8_createLambdaFunction.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dynatrace/AWSMonitoringTutorials/6e3d8899fb3ece7d6673af3660ca859136c14250/images/lab8_createLambdaFunction.PNG
--------------------------------------------------------------------------------
/images/lab8_lambdaExecutionSuccess.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dynatrace/AWSMonitoringTutorials/6e3d8899fb3ece7d6673af3660ca859136c14250/images/lab8_lambdaExecutionSuccess.PNG
--------------------------------------------------------------------------------
/images/lab8_lambdaOptionsScreen.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dynatrace/AWSMonitoringTutorials/6e3d8899fb3ece7d6673af3660ca859136c14250/images/lab8_lambdaOptionsScreen.PNG
--------------------------------------------------------------------------------
/images/lab8_s3bucketURL.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dynatrace/AWSMonitoringTutorials/6e3d8899fb3ece7d6673af3660ca859136c14250/images/lab8_s3bucketURL.PNG
--------------------------------------------------------------------------------
/images/lab8_serverlessIntegration.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dynatrace/AWSMonitoringTutorials/6e3d8899fb3ece7d6673af3660ca859136c14250/images/lab8_serverlessIntegration.PNG
--------------------------------------------------------------------------------
/images/labintro_dynatracedeploy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dynatrace/AWSMonitoringTutorials/6e3d8899fb3ece7d6673af3660ca859136c14250/images/labintro_dynatracedeploy.png
--------------------------------------------------------------------------------