Deploy AppMon Java Agents on Cloud Foundry sample app

Overview

Cloud Foundry is an enterprise PaaS (Platform as a Service.) Cloud Foundry itself is an open source project but a commercial distribution is available from Pivotal. Instructions for setting up a Cloud Foundry demo/development environment utilizing vagrant/virtualbox called bosh-lite is available here: https://github.com/cloudfoundry/bosh-lite.

Requirements

  • Working Cloud Foundry deployment
  • CF command line tools
  • Web server to host agent binaries
  • Gradle
  • Ruby
  • Bundler (gem install bundler)
  • Java Buildpack April 8, 2016 build commit # bed4c6137c7bf08c09813a4b5b33eed0d3eaee46 or later.

Cloud Foundry environments created after the shown date automatically incorporate this build pack. If using an Cloud Foundry environment created after the shown date, Use the latest online Java buildpack. Use -b [https://github.com/cloudfoundry/java-buildpack](https://github.com/cloudfoundry/java-buildpack) or specify using the manifest when pushing applications. You can also create an offline Java buildpack from the latest github repository ( https://github.com/cloudfoundry/java-buildpack) and upload it to PCF.

Prepare a System Profile for cloud foundry Java apps

All applications deployed to Cloud Foundry automatically deploy with the agent name in the format of <CF Application Name>-Monitoring. Add an agent mapping using the ends matching filter:

Create AppMon service

Option one: use the create-user-provided-service command

Point the Cloud Foundry environment at the AppMon Collector. In this example, the Collector is located at 192.168.1.48.

Enter the apprioriate command to create the user provided service.

Note

The syntax differs for each cli environment. For windows environments, double quotes must be escaped with a backslash () the whole command is enclosed in double quotes. Powershell requires double quotes be escaped with a backslash, but encloses the block in a single quote. Further syntax differences can always be found in the cf help create-user-provided-service.

Linux/Mac cf cli:

cf create-user-provided-service cf-dynatrace -p '{"server":"192.168.1.48"}'

Windows:

cf create-user-provided-service cf-dynatrace -p "{\"server\":\"192.168.1.48\"}"

Powershell:

cf create-user-provided-service cf-dynatrace -p '{\"server\":\"192.168.1.48\"}'

If necessary, create a Cloud Foundry security group to allow outbound connectivity to AppMon Collector. Create security.json.

[
{
"protocol": "tcp",
"destination": "192.168.1.48",
"ports": "9998"
}
]

Create dynatrace_group using the following command. Adjust based on the environment.

cf create-security-group dynatrace_group ./security.json

Apply the security group to Cloud Foundry by entering the following.

cf bind-running-security-group dynatrace_group
cf bind-staging-security-group dynatrace_group

Option two: use an AppMon service broker tile and pivotal OpsManager

If necessary, create a Cloud Foundry security group to allow outbound connectivity to the AppMon Collector.
Create security.json.

[
{
"protocol": "tcp",
"destination": "192.168.1.48",
"ports": "9998"
}
]

Create dynatrace_group using the following command. Adjust based on the environment.

cf create-security-group dynatrace_group ./security.json

Apply the security group to Cloud Foundry by entering the following.

cf bind-running-security-group dynatrace_group
cf bind-staging-security-group dynatrace_group

Configuring the AppMon tile

You can access the AppMon Service Broker tile available with PivNet at https://network.pivotal.io/products/p-dynatrace-appmon

  1. Login to Pivotal Ops Manager.
  2. Click on “Import a Product” and import the AppMon tile.
  3. Select the AppMon tile on the left hand panel under Available Products.
  4. Click Add on the AppMon tile.
  5. Select the AppMon tile.
  6. Configure the Availability Zone as shown in the following.
  7. Select Dynamic Service Plans and configure the Dynamic Service Plans as shown in the following.
  8. Click the Add button on the extreme right of the Dynamic Service Plans pane.
  9. Create a separate Service Plan for each AppMon Collector instance to be used.
  10. Configure the AppMon Collector server address and port as shown in the following. Then add additional collectors as needed.
  11. Enable Global Service Access check box for the services to be accessible to all users in Marketplace.
  12. Save configurations and apply your changes.
  13. On completion of the AppMon tile install, check Services Marketplace in Apps Manager.
  14. View the AppMon Service Plan, which should appear similar to the following.
  15. Give the plan an instance name to use with bind-service command and specify the name of the space to add in the Configure Instance tab as shown in the following.

Create and deploy Java sample app

Download and compile spring-music Java application

Use the following command to clone the source for spring-music sample application.

git clone https://github.com/cloudfoundry-samples/spring-music.git

Enter ./gradlew assemble to compile the spring-music application. Compilation may take a few minutes.

Before deploying the application to Cloud Foundry, edit manifest.yml similar to the following to increase the timeout and allow for agent instrumentation time.

---
applications:
- name: spring-music
memory: 512M
instances: 1
timeout: 180
host: spring-music-${random-word}
path: build/libs/spring-music.war

Deploy the Spring Music application to Cloud Foundry, using the --no-start flag to attach AppMon before the application starts.

cf push spring-music-cf -b java_buildpack_dyna --no-start

Attach agents to the application

Cloud Foundry uses a bind mechanism to attach applications to external services. Enter the user provided service name or the plan instance name.

cf bind-service spring-music-cf cf-dynatrace

Start the application

Enter the following to start the Spring Music application.

cf start spring-music-cf

At this point, agents should be deployed along with the application. If the application is scaled to additional instances by Cloud Foundry, new instances are automatically instrumented with AppMon.