- Overview
- Guides
- SDK Guide
- Introduction
- Release Notes
- Context Service Components
- Register Your Application
- Deregister Your Application
- Connect to Context Service
- Context Service Objects
- Search Objects
- Fields and Fieldsets
- Usage Metrics
- View Usage Metrics for Your Organization
- Methods for Usage Metrics
- countValue
- statsSummary
- statsValue
- resetStats
- absoluteCountValue
- absoluteStatsSummary
- absoluteStatsValue
- Get Minimum Latency
- Get Specific Count
- Get Error Count
- Get Counter Summary
- Reset all Statistics
- Get Absolute Minimum Latency
- Get Absolute Count
- Get Absolute Summary
- Clean Up
- End-to-End Example
- Helper Methods
- Errors
- SDK Javadoc
- Customer Context Gadget Control Library
- SDK Guide
- Downloads
- Resources
View Usage Metrics for Your Organization
The Context Service SDK provides methods to look at usage data for your organization, by using the Java Management Extensions (JMX) on your Context Service client connector.
You cannot use JMX on your management connector.
Context Services returns requested statistics by using methods with a specific parameter type and specific operation. For example, to get latency statistics for pod requests created, you specify pod.Create
as your parameter.
The parameters for countValue
and statsValue
are combinations of entities and operations.
Entities include:
- Pod (activity)
- Request
- Customer
- Field
- FieldSet
Operations include:
- Create
- Get
- Delete
- Update
- Search
For example, pod.Create, pod.Get, pod.Delete, pod.Update, pod.Search
are combinations of entities and operations. You can also get metrics for your application using Application.DiscoveryGetList
.
You can get metrics for external types and operations. For example:
- KmsRequest.create_EPHEMERAL_KEY_COLLECTION
- KmsRequest.retrieve_Key
- AccessTokenResponse.AccessToken
- AccessTokenResponse.RefreshToken
You can also get the number of occurrences of an error by passing the parameter type with the error name, using the Get
operator. For example, to see all pod not found errors, specify pod.Get.Error.notFound
.
Statistics are built dynamically upon request, based on usage. If there was no operations executed, you will not see data. For example, if no pods (activities) were created when you request a counter for
pod.Create
, no counter is returned.
Methods for Usage Metrics
Before using metrics on your data, you must connect to your platform Mbean server and get the context server Mbean with ObjectName com.cisco.context:type=ContextServiceClient
. This example shows how to connect to the platform Mbean server:
Copy/**
* Create ContextServiceClient object
*/
public static void registerMbean() throws MBeanException, InstanceNotFoundException, ReflectionException {
mbeanServer = ManagementFactory.getPlatformMBeanServer();
try {
contextObjName = new ObjectName(CONTEXT_OBJECT_NAME);
} catch (MalformedObjectNameException e) {
e.printStackTrace();
}
}
In the example, the Mbean ObjectName
com.cisco.context:type=ContextServiceClient
is defined in the constantCONTEXT_OBJECT_NAME
.
countValue
Use countValue
to get the value of a specific counter since statistics for this client was last reset.
Parameters
countParams
—Combination of the entity and an operation specified as a string. For example,pod.Create
.signature
—Allocates an instance of the classjava.lang.String
.
The method returns the number of the counter of specified type and operation combination.
Example Usage
Object result = Server.invoke(name, "countValue", countParams, signature);
statsSummary
Use statsSummary
to get a full statistics summary as a JSON string of key-value pairs that you can easily converted to a map. In addition to returning all metrics for your organization, statsSummary
also returns:
startCollectionDateTime
—Timestamp from when the data was flushedstatsRequestTime
—Timestamp from when the method was invoked.
You can use this information to calculate the time period that Context Service collected statistics during.
Parameters
statsSummary
does not require any additional parameters.
Example Usage
Object objSummary = Server.invoke(name, "statsSummary", null, null );
statsValue
Use statsValue
to get latency statistics for a particular operation.
Parameters
params
—Combination of a type, an operation, and the statistics to measure specified as a string. For example,pod.Create, min
.
Valid measurement statistics includeavg, min, max, count
.signature
—Allocates an instance of the classjava.lang.String, java.lang.String
.
The method returns a double which is the average, minimum, or maximum latency of the specified type and operation.
Example Usage
Object objSummary = Server.invoke(name, "statsValue", params, signature );
resetStats
Use resetStats
to reset all statistics. By default all statistics are reset every 30 minutes. Call resetStats
to clear all data collected and begin collecting again. Calling resetStats
returns the timestamp indicating the reset time.
Parameters
resetStats
does not require any parameters.
Example Usage
server.invoke(name, "resetStats", null, null );
absoluteCountValue
Use absoluteCountValue
to get the value of a specific counter from the time the client is initialized.
Parameters
params
—Combination of the entity and an operation specified as a string. For example,pod.Create
.signature
—Allocates an instance of the classjava.lang.String
.
The method returns the number of the counter of specified type.
Example Usage
Object result = Server.invoke(name, "absoluteCountValue", params, signature);
absoluteStatsSummary
Use absoluteStatsSummary
to get a full statistics summary as a JSON string of key-value pairs that are easily converted to a map.
In addition to returning all metrics for your organization, absoluteStatsSummary
also returns:
startDateTime
—Timestamp from when the client started.statsRequestTime
—Timestamp from when the method was invoked.
You can use this information to calculate the period of statistics collection.
Parameters
absoluteStatsSummary
does not require any additional parameters.
Example Usage
Object objSummary = Server.invoke(name, "absoluteStatsSummary", null, null );
absoluteStatsValue
Use absoluteStatsValue
to get latency statistics for a particular operation from the time the client was initialized.
Parameters
params
—Combination of a type, an operation, and the measurement statistics specified as a string. For example,pod.Create, min
.
Valid measurement statistics includeavg, min, max, count
.signature
—Allocates an instance of the classjava.lang.String, java.lang.String
.
Example Usage
Object objSummary = Server.invoke(name, "absoluteStatsValue", params, signature );
Get Minimum Latency
This example shows how to get the minimum latency all activities deleted since the last counter reset.
The method takes parameter pod.Create
and the measurement statistics min
and returns a double indicating the latency.
Copy/**
* Get minimum latency of PODs deleted from the time the stats was last reset
* @return Double - It returns the minimum latency of PODs deleted
*/
public static <T> Double invokeStatsValueMethod() throws MBeanException, InstanceNotFoundException, ReflectionException {
final String statsOpName= "statsValue";
final Object[] statsParams= {"pod.Delete", "min"};
final String[] statsValueSignature= new String[]{"java.lang.String", "java.lang.String"};
Object result = mbeanServer.invoke(contextObjName, statsOpName, statsParams, statsValueSignature);
return (Double) result.getClass().cast(result);
}
Get Specific Count
This example shows how to get the count of all activities created since the last counter reset.
Copy/**
* Get the number of PODs created from the time the counter was last reset
* @return Long - It returns the count of PODs created
*/
public static <T> Long invokeCountValueMethod() throws MBeanException, InstanceNotFoundException, ReflectionException {
final String countOpName= "countValue";
final String[] countValueSignature= new String[]{"java.lang.String"};
final Object[] countParams= {"pod.Create"};
Object result = mbeanServer.invoke(contextObjName, countOpName, countParams, countValueSignature);
return (Long) result.getClass().cast(result);
}
Get Error Count
This example shows how to get the number of times getting a deleted activity count threw a notFound
error.
The method takes the parameter pod.Delete.error.errorName
, where errorName
is notFound
.
Copy/**
* Get the number of notFound errors thrown when trying to get a Pod since the counter was last reset
* @return Long -It returns the count of notFound PODs
*/
public static <T> Long invokeCountErrorValueMethod() throws MBeanException, InstanceNotFoundException, ReflectionException {
final String countOpName= "countValue";
final String[] countValueSignature= new String[]{"java.lang.String"};
final Object[] errorCountParams= {"pod.Get.error.notFound"};
Object result = mbeanServer.invoke(contextObjName, countOpName, errorCountParams, countValueSignature);
return (Long) result.getClass().cast(result);
}
Get Counter Summary
This example shows how to get a summary of all statistics measured since the counter was last reset. This method does not take any input parameters. It returns a JSON String that contains all the stats and counts including the timestamp when the collection started and the timestamp when the request was made.
Copy/**
* Get summary of al statistics measured from the time the stats/counter was reset
* @return String - It returns a JSON String that contains all the stats and counters including the timestamp when the collection started and the timestamp when the request was made
*/
public static <T> String invokeStatsSummaryMethod() throws MBeanException, InstanceNotFoundException, ReflectionException {
final String summaryOpName= "statsSummary";
Object result = mbeanServer.invoke(contextObjName, summaryOpName, null, null);
return (String) result.getClass().cast(result);
}
Reset all Statistics
This example shows how to reset all statistics and counts. By default all statistics are rest every 30 minutes. Call this method to clear all data collected and begin collecting again.
Copy/**
* Reset all statistics and counters
*/
public static void invokeResetMethod() throws MBeanException, InstanceNotFoundException, ReflectionException {
final String resetOpName= "resetStats";
mbeanServer.invoke(contextObjName, resetOpName, null, null);
}
Get Absolute Minimum Latency
This example shows how to get minimum latency for all activities deleted since the client was initialized.
The method takes the parameter pod.Delete
and the measurement statistic min
and returns a double indicating the latency.
Copy/**
* Get minimum latency all PODs deleted from the time the client was initialized.
* @return Double - It returns the minimum latency of PODSs deleted
*/
public static <T> Double invokeAbsoluteStatsValueMethod() throws MBeanException, InstanceNotFoundException, ReflectionException {
final String statsOpName= "absoluteStatsValue";
final Object[] statsParams= {"pod.Delete", "min"};
final String[] statsValueSignature= new String[]{"java.lang.String", "java.lang.String"};
Object result = mbeanServer.invoke(contextObjName, statsOpName, statsParams, statsValueSignature);
return (Double) result.getClass().cast(result);
}
Get Absolute Count
This example shows how to get the count of all activities created since the client was initialized.
Copy/**
* Get the count of all POSs created from the time the client was initialized.
* @return Long - It returns the number of PODs created.
*/
public static <T> Long invokeAbsoluteCountValueMethod() throws MBeanException, InstanceNotFoundException, ReflectionException {
final String countOpName= "absoluteCountValue";
final String[] countValueSignature= new String[]{"java.lang.String"};
final Object[] countParams= {"pod.Create"};
Object result = mbeanServer.invoke(contextObjName, countOpName, countParams, countValueSignature);
return (Long) result.getClass().cast(result);
}
Get Absolute Summary
This example shows how to get a summary of all statistics measured since the client was initialized. This method does not take any input parameters. It returns a JSON string that contains all stats and counts, including:
The timestamp from when the collection started.
The timestamp from when the request was made.
javaCopy
/** * Get a summary of all statistics measured since client was initialized * @return String - It returns a JSON String that contains all the stats and counters including the timestamp when the client was initialized and the timestamp when the request was made. */ public static <T> String invokeAbsoluteStatsSummaryMethod() throws MBeanException, InstanceNotFoundException, ReflectionException { final String summaryOpName= "absoluteStatsSummary"; Object result = mbeanServer.invoke(contextObjName, summaryOpName, null, null); return (String) result.getClass().cast(result); }
Clean Up
When you are finished viewing usage metrics, unregister Mbean to clear all data.
Copy/**
* unregister Mbean from MBServer
*/
public static void unregisterMbean() {
try {
ObjectName contextObjName = new ObjectName(CONTEXT_OBJECT_NAME);
if (mbeanServer.isRegistered(contextObjName))
mbeanServer.unregisterMBean(contextObjName);
} catch (JMException ex) {
throw new IllegalStateException(ex);
}
}