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
- 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>
- 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
- Define the Stats/PMI module and create the Stats/PMI object
using StatsFactory.
- Create a class which extends StatisticActions
public class MyStatisticsModule extends StatisticActions
- Declare count variables of type SPI*, such as SPICountStatistc
and SPIBoundedRangeStatistic.
private SPICountStatistic numReqs;
private SPIBoundedRangeStatistic expensiveStat;
- 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);
The
template is the path in the application where the xml file is located;
for example:String template = "/com/stats/MyStats.xml";
- 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 previously 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
}
}
- 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
}
}
- 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 previous example, dataId would
be the id of the statistic that is to be updated.
- Update your application to call methods (defined in the
previous steps) appropriately.
- Access the application.
- Connect Tivoli Performance Viewer and view the custom PMI
statistics.
Evitar Problemas: 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