Introduction
You can write your own logic and attach it to the Monitoring Service. The steps following are required to achieve it.
Create your own monitoring class
Write your own monitoring class which extends the PerformanceMonitor class. Here is an example:
import com.axway.ats.common.performance.monitor.PerformanceMonitor; import com.axway.ats.common.performance.monitor.beans.ReadingBean; public class MyCustomPerformanceMonitor extends PerformanceMonitor { // list with all readings(statistic beans) supported by this custom monitor private ReadingBean importantTableSizeBean; private ReadingBean freeDiskSpaceBean; /** * This method is called when starting monitoring the system * * If needed, some initialization steps could be performed at this point. * For example if you intend to monitor a database, here is the place to establishing a DB connection */ @Override public void init( ReadingBean[] readings ) throws Exception { // Check which statistics our user is interested in. // In order to do that you have to iterate over the array which is passed to this method as input argument // and see the names of the passed readings. // For example if readings[0].getName() returns "Important table size", we can simply do the following: importantTableSizeBean = readings[0]; // Do not assume the user wants to get info about all supported statistics. // In our example we support 2 kinds of statistics but it is possible that // in some test only one of these statistics is wanted, // so you have to make such check here } /** * This method is called when stopping monitoring the system * * If needed, release some resources, for example a DB connection */ @Override public void deinit() throws Exception { } /** * This method will be called just once. * * It must return a list with the needed statistics in the form of ReadingBean. * This will provide the same data as the ReadingBean, but in addition it will provide the statistic * names and units */ @Override public List<ReadingBean> pollNewDataForFirstTime() throws Exception { // make an array where we will fill the current poll results List<ReadingBean> results = new ArrayList<ReadingBean>(); // if user requested this reading - make a new poll now if( importantTableSizeBean != null ) { importantTableSizeBean.setValue( getImportantTableSize() ); results.add( importantTableSizeBean ); } // if user requested this reading - make a new poll now if( freeDiskSpaceBean != null ) { freeDiskSpaceBean.setValue( getFreeDiskSpace() ); results.add( freeDiskSpaceBean ); } return results; } /** * Once the pollNewDataForFirstTime() is called, then only the pollNewData() method * is called in regular intervals and is supposed to return the actual monitoring data * * It must return a list of ReadingBean which contain unique statistic id and current value */ @Override public List<ReadingBean> pollNewData() throws Exception { // make an array where we will fill the current poll results List<ReadingBean> results = new ArrayList<ReadingBean>(); // if user requested this reading - make a new poll now if( importantTableSizeBean != null ) { ReadingBean importantTableSizeBean = importantTableSizeBean.getNewCopy(); importantTableSizeBean.setValue( getImportantTableSize() ); results.add( importantTableSizeBean ); } // if user requested this reading - make a new poll now if( freeDiskSpaceBean != null ) { ReadingBean freeDiskSpaceBean = freeDiskSpaceBean.getNewCopy(); freeDiskSpaceBean.setValue( getFreeDiskSpace() ); results.add( freeDiskSpaceBean ); } return results; } @Override public String getDescription() { // provide some name, that will be seen in the logs return "My Custom Monitor"; } private String getImportantTableSize() { // fill in this custom method body, // so it returns the size of the important table } private String getFreeDiskSpace() { // fill in this custom method body, // so it returns the free disk space } }
Create a custom.performance.configuration.xml
This file describes your supported readings
<?xml version="1.0" encoding="utf-8"?> <configuration> <monitor class="com.test.MyCustomPerformanceMonitor"> <reading name="Important table size" unit="Number" /> <reading name="Free disk space" unit="MB" /> </monitor> </configuration>
Note that you may have multiple <monitor> nodes with multiple <reading> nodes.
This file goes in the classpath root and is recommended to be in the root of the custom monitor jar.
Deploy the custom monitor
Package your monitoring class into a JAR and deploy it to the <AGENT HOME>/actions_dependencies folder on the monitored host.
Now you can call your monitor in the same way as the regular ones:
systemMonitor.scheduleSystemMonitoring( <MONITORING SERVICE IP AND PORT>, new String[]{ SystemMonitor.MONITOR_CPU.ALL, SystemMonitor.MONITOR_IO.ALL, SystemMonitor.MONITOR_MEMORY.ALL, SystemMonitor.MONITOR_VIRTUAL_MEMORY.ALL, SystemMonitor.MONITOR_NETWORK_INTERFACES.ALL, "Important table size", "Free disk space" } );
Now go to Test Explorer UI to see your result
Back to parent page
Go to Table of Contents