WAS v8.5 > Monitoring > Monitoring overall system health > Develop custom PMI monitoring applications > Run your new monitoring applications

Create a custom PMI using StatsFactory

We can update the application to call methods defined using A Stats/PMI template (Performance Monitoring Infrastructure), resource bundle, Stats/PMI module and methods to update custom statistics. We can update the 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:

  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. We can assign statistics declared above to the appropriate statistic; for example:
    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 the application will use to update custom statistics.
    public void onRequestArrival(){
         if (numReqs != null)
            {
                numReqs.increment();         ---> Increment/Decrement Statistic as per Req}
  6. We 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 the application to call methods (defined in above steps) appropriately.
  8. Access the application.
  9. Connect Tivoli Performance Viewer and view the custom PMI statistics.

    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 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


+

Search Tips   |   Advanced Search