vangu02

Using the APM Introscope API to query data

Blog Post created by vangu02 Employee on Feb 9, 2016

Ever asked yourself how you can query metrics data from the APM Smartstor? Easy, just use the Web Service described on ca.com CA Introscope Web Services API Reference

 

Let’s see how that works in an example, for this I will use the Metrics Data Web Service, with wsdl described here:  Metrics Data Web Service WSDL Definition

 

In that wsdl you find 3 operations: getLiveMetricData, getMetricData and getTopNMetricData.

 

Suppose I want the metrics for a certain timeframe, I then would use getMetricData.

 

The Web Service exposed is a SOAP webservice, and there are some ways to use that. I prefer generating java code from the wsdl, and the Axis libraries conveniently offer a simple way of doing that. I will use wsdl2java (no surprise here) for that.

 

How do you create an Axis client?

 

Some interesting reading before creating the axis clients you find here: https://axis.apache.org/axis/java/reference.html .

  1. download axis libraries from here: http://www.apache.org/dyn/closer.cgi/axis/axis/java/1.4/
  2. execute WSDL2Java against the WSDL
    1. java -cp axis.jar;wsdl4j-1.5.1.jar;commons-logging-1.0.4.jar;commons-discovery-0.2.jar;jaxrpc.jar;mailapi.jar org.apache.axis.wsdl.WSDL2Java WSDL-URI
    2. where WSDL-URI in this example is : http://<host>:<port>/introscope-web-services/services/MetricsDataService?wsdl

 

This creates two packages, to use them you include these sources in your project. Don’t forget to add Axis libraries, your runtime will fail without them.

 

Use the generated java code

 

Now you can start using the Introscope SOAP Web Service, like shown in this code snippet:

 

# Create a locator – with http://<host>:<port>/introscope-web-services/services/MetricsDataService as soapEndPoint

 

MetricsDataServiceLocator locator = new MetricsDataServiceLocator();

  1. locator.setMetricsDataServiceEndpointAddress(soapEndPoint);

 

# use the locator to bind to a stub and the getMetricsDataService

 

MetricsDataServiceSoapBindingStub stub = new MetricsDataServiceSoapBindingStub(locator);

stub = (MetricsDataServiceSoapBindingStub) locator.getMetricsDataService();

 

# set the correct username/password on the stub (blank passwords will fail)

             

  1. stub.setUsername(username);
  2. stub.setPassword(password);

# get the metrics

TimesliceGroupedMetricData[] returnedData = stub.getMetricData(agent, metric, starttime, endtime, dataFrequency);

# Now start using the returned data

long measuretime = returnedData[i].getTimesliceStartTime().getTimeInMillis();

 

mData = returnedData[i].getMetricData();

 

Working example

 

As a working example you can have a look at http://github.com/CA-APM/SOAP2REST

 

Here I have used the Web Service to query metrics and expose them as a json thru a REST Web Service.

 

Usage and example:

GET http://rest-host:port/RESTgtw/rest?interval=INTERVAL&agent=AGENTEXPRESSION&metric=METRICEXPRESSION(&end=INTERVALEND)

example: http://localhost:8310/RESTgtw/rest?interval=7200&agent=(.)|(.)|(.)&metric=TEST(.):(.) http://localhost:8310/RESTgtw/rest?interval=7200&agent=(.)|(.)|(.)&metric=TEST(.):(.)&end=29 10 2015 18:00:00

POST (application/json) http://localhost:8310/RESTgtw/rest { "agent": "AGENTEXPRESSION", "metric": METRICEXPRESSION, "interval" : INTERVAL, ("end": INTERVALEND) }

example: { "agent": "(.)|(.)|(.)", "metric": "Frontends(.):(.*)", "interval" : 7200, "end": "19 10 2015 18:00:00" }

 

Feel free to copy/fork/expand this code, all feedback is welcome !

 

Happy coding!

 

Guy.

 

Outcomes