Accessing Your Performance Data with the AppDynamics REST API
Join the DZone community and get the full member experience.
Join For FreeApp 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:
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:
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 for 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.
Published at DZone with permission of Dustin Whittle, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments