AppDynamics Application Performance Monitoring for PCF Workflow

This topic describes how to push and bind an application to an AppDynamics tile.

Before You Start

  1. Create a Pivotal Network account if you do not have one.

  2. Install the Cloud Foundry Command Line Interface (cf CLI). See Installing the cf CLI.

Create an AppDynamics Service Instance

  1. Open a cf CLI or command-prompt window.

  2. Identify your Pivotal API endpoint and version. Enter the following command:

    $ cf api
    The following output appears:
    api endpoint: https://api.my.pivotal.io
    api version: 2.103.0
    

  3. Log in to the Pivotal endpoint:

    cf login

  4. Enter your email address and Pivotal password when prompted.

  5. Verify the appdynamics service is present in the cf environment.

    $ cf marketplace -s appdynamics
    service plan                   description                    free or paid
    pcf-appd                       pcf-appd                       free
    pcf-appd-troubleshooting-lab   pcf-appd-troubleshooting-lab   free
    

  6. Create a service instance of the appdynamics service and a plan of your choice.

    $ cf create-service appdynamics pcf-appd appd
    

  7. Follow the workflow for the corresponding language of the application mentioned below

AppDynamics Instrumentation Workflows

.NET Framework Applications (Multiple Buildpack)

DotNet Framework Applications are pushed using standard hwc_buildpack. These applications are instrumented using appdbuildpack in tandem with hwc_buildpack using the multiple buildpack approach.

  1. Edit the following sections of your application’s manifest.yml

  2. Include appdbuildpack in the buildpacks section.

  3. Set the application environment variable APPD_AGENT to dotnet

  4. Bind the application to the appdynamics service instance, by including appd in the services section of the application manifest.

    ---
    applications:
    - name: cf-net
      memory: 2G
      buildpacks: 
        - appdbuildpack
        - hwc_buildpack
      stack: windows2016
      env:
        APPD_AGENT: dotnet 
      services:
        - appd
    
  5. Push the application using the cf push command.

    $ cf push 

Advanced configuration

appdbuildpack provides APPD_AGENT_HTTP_URL and APPD_CONF_HTTP_URL environment variables to customize agent binary downloads and extend agents advanced configuration respectively. See AppDynamics MultiBuildPack documentation for details.

.NET Core Linux Applications (MultiBuildPack)

  1. Edit the following sections of your application’s manifest.yml

  2. Include appdbuildpack in the buildpacks section.

  3. Set the application environment variable APPD_AGENT to dotnet-linux

  4. Bind the application to the appdynamics service instance, by including appd in the services section of the application manifest.

    ----
    applications:
    - name: cf-net-linux
      memory: 2G
      buildpacks: 
        - appdbuildpack
        - dotnet_core_buildpack
      env:
        APPD_AGENT: dotnet-linux
      services:
        - appd
    
  5. Push the application using the cf push command.

    $ cf push 

Advanced configuration

appdbuildpack provides APPD_AGENT_HTTP_URL and APPD_CONF_HTTP_URL environment variables to customize agent binary downloads and extend agents advanced configuration respectively. Refer AppDynamics MultiBuildPack documentation for details.

.NET Core Windows Applications (MultiBuildPack)

DotNet Core Applications for Windows are pushed using standard binary_buildpack. Such applications are instrumented using appdbuildpack in tandem with binary_buildpack using multiple buildpack approach.

  1. Edit the following sections of your application’s manifest.yml

  2. Include appdbuildpack in the buildpacks section

  3. Set the application environment variable APPD_AGENT to dotnet-windows

  4. Bind the application to the appdynamics service instance, by including appd in the services section of the application manifest.

    ---
    applications:
    - name: cf-net-windows
      random-route: true
      memory: 512M
      path: app.zip
      command: dotnetHelloWorld.exe
      stack: windows2016
      buildpacks:
        - appd_buildpack
        - binary_buildpack
      env:
        APPD_AGENT: dotnet-windows
        DOTNET_CLI_TELEMETRY_OPTOUT: 1
        DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
      services:
        - appd
    
  5. Push the application using the cf push command.

    $ cf push 

Advanced configuration

appdbuildpack provides APPD_AGENT_HTTP_URL and APPD_CONF_HTTP_URL environment variables to customize agent binary downloads and extend agents advanced configuration respectively. Refer AppDynamics MultiBuildPack documentation for details.

Python Applications (MultiBuildPack)

Python Applications are pushed using standard python_buildpack. Such applications are instrumented using appdbuildpack in tandem with python_buildpack using the multiple buildpack approach.

  1. Edit the following sections of your application’s manifest.yml

  2. Include appdbuildpack in the buildpacks section of application manifest.

  3. Set the application environment variable APPD_AGENT to python

  4. Bind the application to the appdynamics service instance, by including appd in the services section of the application manifest.

    ---
    applications:
    - name: cf-python
      memory: 500M
      buildpacks: 
        - appdbuildpack
        - python_buildpack
      env:
        APPD_AGENT: python
      services:
        - appd
    
  5. Push the application

    $ cf push 

Advanced configuration

appdbuildpack provides APPD_AGENT_HTTP_URL and APPD_CONF_HTTP_URL environment variables to customize agent binary downloads and extend agents advanced configuration respectively. Refer AppDynamics MultiBuildPack documentation for details.

GoLang Applications (MultiBuildPack)

Go Applications are pushed using the standard go_buildpack. AppDynamics provides an SDK to instrument such applications. The configuration needed to start the go agent via the SDK APIs is exported as environment variables when the applications are pushed with appdbuildpack and go_buildpack using the multiple buildpack approach.

  1. Edit the following sections of your application’s manifest.yml

  2. Include appdbuildpack in the buildpacks section of application manifest.

  3. Set the application environment variable APPD_AGENT to golang

  4. Bind the application to the appdynamics service instance, by including appd in the services section of the application manifest.

    ---
    applications:
    - name: cf-go
      memory: 500M
      buildpacks: 
        - appdbuildpack
        - go_buildpack
      env:
        APPD_AGENT: golang
      services:
        - appd
    
  5. Copy paste the below snippet to initialize the go agent.

      package main
      import (
          ... 
          appd "appdynamics"
      )
    
        ...
          cfg := appd.Config{}
          cfg.AppName = os.Getenv("APPD_APPLICATION_NAME")
          cfg.TierName = os.Getenv("APPD_TIER_NAME")
          cfg.NodeName = os.Getenv("APPD_NODE_NAME")
    
          /* AppDynamics Controller Confiuration */
          cfg.Controller.Host = os.Getenv("APPD_CONTROLLER_HOST")
          port, err := strconv.ParseInt(os.Getenv("APPD_CONTROLLER_HOST"), 10, 16)
          if err != nil {
            return err
          }
          cfg.Controller.Port = uint16(port)
          cfg.Controller.Account = os.Getenv("APPD_ACCOUNT_NAME")
          cfg.Controller.AccessKey = os.Getenv("APPD_ACCOUNT_ACCESS_KEY")
          cfg.InitTimeoutMs = 1000
    
          err = appd.InitSDK(&cfg)
          if err != nil {
              fmt.Println(err)
          }
          ... 
    
  6. The necessary configuration to start AppDynamics Golang agent is exposed via environment variables APPD_APPLICATION_NAME, APPD_TIER_NAME, APPD_NODE_NAME, APPD_CONTROLLER_HOST, APPD_CONTROLLER_HOST, APPD_ACCOUNT_NAME, APPD_ACCOUNT_ACCESS_KEY

  7. Push the application

    $ cf push 

Advanced configuration

The appdbuildpack provides APPD_AGENT_HTTP_URL and APPD_CONF_HTTP_URL environment variables to customize agent binary downloads, and extend agents advanced configuration respectively. See AppDynamics MultiBuildPack documentation for details.

Java Applications

Java applications are instrumented by AppDynamics using standard java_buildpack.

  1. Edit the following sections of your application’s manifest.yml

  2. Bind the application to the appdynamics service instance, by including appd in the services section of the application manifest.

    ---
    applications:
    - name: cf-java-app
      memory: 1G
      random-route: true
      path: build/libs/cf-java-sample-1.0.jar
      buildpacks:
        - java_buildpack
      services:
        - appd
    
  3. Push the application

    $ cf push 

Advanced configuration

Because AppDynamics instrumentation of pcf java applications does not use appdbuildpack, the configuration is managed by java_buildpack directly.

Refer standard java_buildpack documentation

Node.js Applications

Node.js applications are instrumented by AppDynamics using standard nodejs_buildpack directly.

  1. Edit your application and paste the following in your application at the beginning of your application source code, before any other require statement.

      var cfEnv = require('cfenv');
      var appEnv = cfEnv.getAppEnv();
      var appdService = appEnv.getServiceCreds('pcf-appd-instance');
      var appdynamics = require("appdynamics").profile({
          controllerHostName: appdService['host-name'],
          controllerPort: appdService['port'],
          controllerSslEnabled: appdService['ssl-enabled'],
          accountName: appdService['account-name'],
          accountAccessKey: appdService['account-access-key'],
          nodeName: `${appEnv.name}.${process.env.CF_INSTANCE_INDEX}`,
          libagent: true
      });
    
  2. Add appdynamics package in the list of dependencies specified in your package.json

        ....
        "dependencies": {
          "express": "~4.15.2",
          "logfmt": "~1.2.0",
          "appdynamics": "latest",
          "cfenv": "latest"
        },
        ...
    
  3. Bind the application to the appdynamics service instance, by including appd in the services section of the application manifest.

    applications:
    - name: cf-node
      memory: 500M
      services:
        - appd
    
  4. Push the application

    $ cf push 

Extending Default Configuration

Extending Application, Tier, Node names

To override the the default AppDynamics application/tier/node names, set the following environment variables.

$ cf set-env APP ENV-NAME ENV-VALUE 
AGENT APPLICATION ENV VARIABLE TIER ENV VARIABLE NODE ENV VARIABLE
Python APPD_APP_NAME APPD_TIER_NAME APPD_NODE_NAME
Java APPDYNAMICS_AGENT_APPLICATION_NAME APPDYNAMICS_AGENT_TIER_NAME APPDYNAMICS_AGENT_NODE_NAME
NodeJS APPDYNAMICS_AGENT_APPLICATION_NAME APPDYNAMICS_AGENT_TIER_NAME APPDYNAMICS_AGENT_NODE_NAME
Golang APPD_APP_NAME APPD_TIER_NAME APPD_NODE_NAME
.NET APPDYNAMICS_AGENT_APPLICATION_NAME APPDYNAMICS_AGENT_TIER_NAME APPDYNAMICS_AGENT_NODE_NAME
PHP APPD_APP_NAME APPD_TIER_NAME APPD_NODE_NAME

Extending Proxy configuration

If you are using a proxy server, the consumer application should specify the http_proxy or https_proxy as an environment variable for the application running on PCF to communicate with the proxy server. Do the following:

  1. Set the environment variable for the application and the Controller.

    • For an HTTP proxy:
      cf set-env  http_proxy http://user@password:myproxy....:8080/
    • For an HTTPS proxy:
      cf set-env  https_proxy https://user@password:myproxy....:8080/
  2. Restage the application:

    cf restage 

  3. Log in to the Controller web UI, navigate to the Metric Browser, and verify that the application is being detected and monitored.

Using AppDynamics User Provided Service

In addition to the above procedure using service broker tile, operators can also use user provided service with name appdynamics to instrument applications on AppDynamics.

  1. Use the below cf cups command with the JSON fields specified below

  2. The name of the user provided service must be appdynamics and it’s JSON credentials must have account-access-key, account-name, host-name, port and ssl-enabled fields.

$ cf cups appdynamics -p '{"account-access-key":"acce$$key", "account-name":"customer1", "host-name":"demo.appdynamics.com", "port":"8090", "ssl-enabled":false}' 
Create a pull request or raise an issue on the source for this page in GitHub