Creating a custom PMI using StatsFactory

You can update your application to call methods defined using A Stats/PMI template (Performance Monitoring Infrastructure), resource bundle, Stats/PMI module and methods to update custom statistics.

About this task

You can update your application to call methods defined using A Stats/PMI template, resource bundle, Stats/PMI module and methods to update custom statistics. The following process is required to instrument a component using a custom PMI:
  • Define a Stats/PMI template (xml file).
  • Define the resource bundle (properties file).
  • Define the Stats/PMI module and create the Stats/PMI object using StatsFactory.
  • Define methods that your application will use to update custom statistics.
  • Update your application to call methods (defined in the preceding step) appropriately.
  • Access the application.
  • Connect to the Tivoli Performance Viewer (TPV) and view the Custom PMI statistics.

Procedure

  1. Define the Stats/PMI template. StatsFactory allows a runtime component to create a custom Stats/PMI module using an XML template. The template should follow the DTD com/ibm/websphere/pmi/xml/stats.dtd. The following is an example of a template used in a sample application.
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE Stats SYSTEM "stats.dtd">
    
    <Stats type="com.stats.MyStats">
        <description>MyStats.desc</description>
        <resourceBundle>com.stats.MyStatsResourceBundle</resourceBundle>
        								
        <CountStatistic ID="1" name="MyStats.NumRequests">
            <level>low</level>
            <unit>MyStats.unit.none</unit>                
            <description>MyStats.NumRequests.desc</description>   
            <statisticSet>basic</statisticSet>             
        </CountStatistic>
    
     
        <BoundedRangeStatistic ID="2" name="MyStats.expensiveStat ">
            <level>high</level>
            <unit>MyStats.unit.none</unit>
            <description>MyStats.expensiveStat.desc</description>
            <updateOnRequest>true</updateOnRequest>        
        </BoundedRangeStatistic>    
    </Stats>
  2. Define the resource bundle The resource bundle allows you to define the name of statistic and its description in proper language/wording. A sample resource bundle would look like this:
    MyStats.desc=My View PMI Module
    
    MyStats.NumRequests=Request Count
    MyStats.NumRequests.desc=Total number of My view requests served. 
    MyStats.unit.none=None
    
    
    MyStats.expensiveStat = Expensive Stat
    MyStats. expensiveStat.desc = Number of Expensive stats 
    
    MyStats.Group= My Group
    MyStats.Instance=My Instance 
  3. Define the Stats/PMI module and create the Stats/PMI object using StatsFactory.
    1. Create a class which extends StatisticActions
      public class MyStatisticsModule extends StatisticActions 
    2. Declare count variables of type SPI*, such as :SPICountStatistc and SPIBoundedRangeStatistic.
      private SPICountStatistic           numReqs;
      	private SPIBoundedRangeStatistic    expensiveStat;
    3. Create StatsGroup of type StatsGroup and StatsInstance of type StatsInstance
      private static StatsGroup stocksStatisticsGroup = null;
      	private StatsInstance stocksStatistics = null;
      
      
      MyStatisticsGroup = StatsFactory.createStatsGroup("MyStats.Group", template, null);
      MyStatistics = StatsFactory.createStatsInstance("MyStats.Instance”,MyStatisticGroup,null,this);
      where the template would be the path in the application where the xml file is located. An example of this follows:
      String template = "/com/stats/MyStats.xml";
  4. Once the Statistics are created in the StatsInstance, statisticCreated is called to indicate that a statistic is created in the Stats instance. .You can assign statistics declared above to the appropriate statistic. An example follows:
    public void statisticCreated (SPIStatistic s)      --> Called when the Statistics are
     created in the Stats Instance
        	{
        	if (s.getId() == MyStats.NUMREQS)
            	{
                	numReqs = (SPICountStatistic)s;		     ---> Assign Statistic 
            }
    }
  5. Define methods which your application will use to update custom statistics.
    public void onRequestArrival(){
        	if (numReqs != null)
            {
                numReqs.increment();         ---> Increment/Decrement Statistic as per Req
    }
  6. You can also implement the updateStaisticRequest method to update statistics on a specific request by the client or any other monitoring application.
    public void updateStatisticOnRequest (int dataId)
    		{
    if (dataId == MyStats.expensiveStat)
           		{
            		expensiveStat.set(xxxxx);        
    		}
    
    }	
    In the above example, dataId would be the id of the statistic that is to be updated.
  7. Update your application to call methods (defined in above steps) appropriately.
  8. Access the application.
  9. Connect Tivoli Performance Viewer and view the custom PMI statistics. [Updated in July 2012]
    Avoid trouble Avoid trouble: When a custom PMI is implemented in a network deployment environment, you may not be able to view the custom PMI counters because the Stats/PMI xml file and the resource bundle property file are not visible to the WebSphere Application Server class loader. The Stats/PMI.xml file and the resource bundle property file are present inside the application. To be able to view the custom PMI counters, you need to place the Stats/PMI.xml file and the resource bundle property file in the class path.
    You make the custom PMI counters visible by creating a jar with the following file structure of the Stats/PMI.xml file and resource bundle property file and place them in the WAS_HOME\lib\ext folder. The custom PMI counters are then visible to the class loader.
    com/ibm/app/temp/tempstats.xml        --- path of the Stats/PMI.xml
    com/ibm/app/temp/resourcebundle.props --- path of the resource bundle property file
    gotcha
    [Updated in July 2012]
    jul2012



In this information ...


IBM Redbooks, demos, education, and more

(Index)

Use IBM Suggests to retrieve related content from ibm.com and beyond, identified for your convenience.

This feature requires Internet access.

Task topic Task topic    

Terms and conditions for information centers | Feedback

Last updatedLast updated: Feb 6, 2014 8:11:25 PM CST
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=matt&product=was-nd-mp&topic=tprf_stats_pmi
File name: tprf_stats_pmi.html