18 March 2016

Learn How to Get Your AppDynamics Metrics in Load Impact Test Results


tl;dr — With a few quick steps, engineers who use AppDynamics as their Application Performance Monitoring solution can see server behavior in their Load Impact tests.

This example shows how to get a single CPU metric from AppDynamics into Load Impact test results using the Load Impact Server Metrics Agent

  1. Make sure your AppDynamics agents are properly set up, configured and running with your application. If you're reading this, chances are you're an AppDynamics user, so you're probably good there.

  2. Get your Load Impact Server Monitoring Agent and install it on your server.

    See this Knowledge Base Article if this is not already set up

  3. Go into your AppDynamics panel and find the REST API URL for the particular metric you want to collect.

    Example here: http://community.appdynamics.com/t5/AppDynamics-Discussions/Rest-APIs/td-p/18856

    For our example, our CPU metric is the following

    Assuming you have installed your Load Impact Server Metrics Agent on a windows box, create a powershell script containing this (named appdynamics_cpu.ps1):

    $user = "myppadynamicsuser@myappdynamicsaccount"
    $password = "<myappdynamicspassword>"
    $uri = https://loadimpact.saas.appdynamics.com/controller/rest/applications/GSSTO002/metric-data?metric-path=Application%20Infrastructure%20Performance%7CMachine%20Agent%7CHardware%20Resources%7CCPU%7C%25Busy&time-range-type=BEFORE_NOW&duration-in-mins=1
    $auth = 'Basic ' + [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($user+":"+$password ))
    $req = New-Object System.Net.WebClient
    $req.Headers.Add('Authorization', $auth)
    [xml]$resp = $req.DownloadString($uri)
    $cpu = $resp."metric-datas"."metric-data".metricValues."metric-value".value
    "AppDynamics CPU | 'AppDynCPU'=$cpu"
  4. And to be able to run the powershell script we are somewhat lazy (and skip setting up proper authorization and authentication on our windows box, do not do this in your production environment and create a cmd file containing this (named appdynamics.cmd):

    powershell -noprofile -ExecutionPolicy Bypass -f "c:\Server Metrics Agent\appdynamics_cpu.ps1"
    EXIT /B 0
  5. Now to the interesting part, how to get that into Load Impact!

    Open the li_metrics_agent.conf file located in your server metrics agent install folder. On a windows box that typically is c:\server metrics agent.

    Find the section that starts with

    # An external script
    # The script needs to output data in the Nagios performance data format, see:
    # http://nagiosplug.sourceforge.net/developer-guidelines.html#AEN201

    This section is where you add any and all extra metrics to collect during the test run.

    Add this:

    # CPU usage from AppDynamics
    command = "c:/Server Metrics Agent/appdynamics.cmd"

    Save and recycle your server metrics agent service (it’s aptly named Load Impact Server Metrics Agent Service) to pick up the configuration changes.
  6. The next time you run your test and include the server metrics agent in the test config (see #1 for usage) you will get the AppDynamics metric included so you can plot like this:


    And for those of you not deploying the Load Impact Server Metrics Agent on windows but rather on a \*nix this shell script (named appdynamics.sh in this example) will output the same thing as the cmdfile/powershell combo on windows (it uses curl to call the REST API, get here if you don’t have it http://curl.haxx.se/):

    echo "AppDynamics CPU|'AppDynCpu='"$(curl -s -G -u myappdynamicsuser@myappdynamicsaccount:myappdynamicspassword "https://loadimpact.saas.appdynamics.com/controller/rest/applications/GSSTO002/metric-data?metric-path=Application%20Infrastructure%20Performance%7CMachine%20Agent%7CHardware%20Resources%7CCPU%7C%25Busy&time-range-type=BEFORE_NOW&duration-in-mins=1" | grep -oPm1 "(?<=<value>)[^<]+")

    And just for clarity you would add this line to your `li_metrics_agent.conf`

    # CPU usage from AppDynamics
    command = "appdynamics.sh"

Now that you know how to do it, go find your analytics metrics in AppDynamics, include them in your test runs and enjoy correlating analytics and results at the speed of test!

< Back to all posts