Accessing your performance data with the AppDynamics REST API

image_pdfimage_print

App Man previously covered how to go mobile with the AppDynamics REST API and Dojo highlighting the AppDynamics Gauges project. In this post, we will cover how to get the most out of AppDynamics by leveraging the REST API.

Custom Dashboards

AppDynamics comes with very powerful and sexy custom dashboards that anyone can build. With our custom dashboards you can combine and graph any metric and easily come up with an ops- or business- focused dashboard for your executive team.

DevOps Dashboard:

DevOps Dashboard

Management Dashboard:

Management Dashboard

Get started building a custom dashboard.

Sometimes a custom dashboard is not enough and you really need the data underneath. If our amazing HTML5 custom dashboards are not enough, at the end of the day your data is yours. The goal of this post is to provide an introduction on how to access your performance data.

AppDynamics is extensible

AppDynamics Pro allows you to track any custom metric through the machine agent. This means you can easily track any application metrics via AppDynamics and use the REST api to mashup the data (think of it as a replacement for the popular StatsD and Graphite combination). The REST API allows you to access metrics and mashup your data with your internal tools.

How to access performance data via REST API

From within the AppDynamics metrics browser you can easily access the url for the API for a particular metric by right clicking as shown here:

REST_URL

Access data via the command line

Once you have the API endpoint needed for the metrics you want you can easily access it via curl on the command line. Our REST API uses HTTP basic authentication. If you have installed the Controller on a single-tenant platform, your default account is:

Username: username@customer1
Password: xxxx

If you are using the SaaS Controller, your username is your AppDynamics user name in your AppDynamics account:

username@accountname

The credentials are the same you use to log in to the controller. Below are common examples:

Retrieve a list of applications available


curl --user username@example:password 'http://example.saas.appdynamics.com:8090/controller/rest/applications?output=JSON'

[
    {
    "description": "",
    "id": 7,
    "name": "AppDynamics"
  },
    {
    "description": "",
    "id": 5,
    "name": "Knp Ipsum"
  }
]
Retrieve the average response time of a specific application


curl --user username@example:password 'http://example.saas.appdynamics.com:8090/controller/rest/applications/AppDynamics/metric-data?metric-path=Overall%20Application%20Performance%7CAverage%20Response%20Time%20(ms)&time-range-type=BEFORE_NOW&duration-in-mins=60&output=JSON'

[{
  "frequency": "ONE_MIN",
  "metricPath": "Overall Application Performance|Average Response Time (ms)",
  "metricValues": [  {
    "current": 41,
    "max": 131,
    "min": 9,
    "startTimeInMillis": 1375298040000,
    "value": 50
  }]
}]
Retrieve number of requests per minute for a specific application


curl --user username@example:password 'http://example.saas.appdynamics.com:8090/controller/rest/applications/AppDynamics/metric-data?metric-path=Overall%20Application%20Performance%7CCalls%20per%20Minute&time-range-type=BEFORE_NOW&duration-in-mins=15&output=JSON'

[{
  "frequency": "ONE_MIN",
  "metricPath": "Overall Application Performance|Calls per Minute",
  "metricValues": [  {
    "current": 2,
    "max": 0,
    "min": 0,
    "startTimeInMillis": 1375300860000,
    "value": 2
  }]
}]
Getting started with the REST API via SDKs

The easiest way to get started working with the REST API is to use the SDK available for Java and Python. The SDKs provide a lightweight wrapper around our REST API and are available via AppDynamics X. The AppDynamics REST API offers XML and JSON for interoperability.

Accessing the REST API via the Python SDK


from appd.cmdline import parse_argv
from appd.request import AppDynamicsClient


args = parse_argv()
c = AppDynamicsClient(args.url, args.username, args.password, args.account, args.verbose)
for app in c.get_applications():
print app.name, app.id

The best example is for fetching metrics for business transactions. Checkout the Python SDK for more examples.

How to track a custom metric with machine agent

The machine agent can act as a REST gateway to capture custom metrics into the AppDynamics metrics browser. In order to enable the machine agent API, start the machine agent with the following options:


sudo java -Dmetric.http.listener=true -Dmetric.http.listener.port=8293 -jar /opt/appdynamics/machine-agent/machineagent.jar

Once the machine agent is listening, tracking custom metrics is as easy as making a post request to:

http://localhost:8293/machineagent/metrics?name=foo|bar&value=42&type=average

Going even farther

Two weeks ago we announced AppDynamics X where we released many integrations that leverage the machine agent to track custom metrics from Nginx, Apache, Cassandra, and more. The real power of AppDynamics is not the user interface, but the stats and business intelligence platform under the hood.

As always, please feel free to comment if you think I have missed something or if you have a request for content for an upcoming post.

  • smurf

    Hi,

    Is it possible to use the REST API to export raw data for a time period?

    For example:

    “avg response time” grouped hourly for the past 3 days.

    I do this now manually in the UI and exporting to CSV. The end goal is to save this data into a datastore for later mining and reporting. Worst case I could have a crontab run hourly and poll the metrics I want to save to my DB.

    Any suggestions are appreciated.
    Thanks
    -Sean

    • http://www.appdynamics.com/ Jim Hirschauer

      Hi Sean,

      Yes, using the REST API is a great way to export the raw data for a time period programatically. Your example is really easy to accomplish (hint: right click on the metric name in the metric browser, copy REST URL) and you can find out all the details by accessing the documentation here… http://docs.appdynamics.com/display/PRO13S/Use+the+AppDynamics+REST+API

      You will need a login to our support portal to access the link I provided. A couple of parameters to pay attention to are “rollup” (controls whether you get 1 data point or all data points) and “output” (controls whether you get XML or JSON output).

Copyright © 2014 AppDynamics. All rights Reserved.