Adding Statistics for a Component to the Monitorable
Object Tree

Adding statistics for a component to the monitorable object tree makes
the component and its statistics monitorable objects.

Adding a statistics for a component to the monitorable object tree involves
the following tasks:

Creating a TreeNode object to represent
the component in the monitorable object tree

Creating objects to represent the component's statistics in
the monitorable object tree

Getting the server node object

Adding each object to the tree

Creating a TreeNode Object
to Represent a Component

To a create a TreeNode object to represent a
component in the monitorable object tree, invoke the static method createTreeNode of the org.glassfish.flashlight.datatree.factory.TreeNodeFactory class. Invoke this method in the class that represents your
component.

In the invocation of the createTreeNode method,
pass the following information as parameters to the method:

A string that contains the name of the node

An instance of the class that represents the component

A string that describes the category of the component

Creating Objects to Represent a Component's Statistics

Create one object to represent each statistic that you are adding to
the monitorable object tree. Create the objects in your listener class or
in the class that represents your add-on component. Each object must be an
implementation of an interface that extends org.glassfish.flashlight.datatree.TreeNode.

Note –

The TreeNode is an unstable interface
and is subject to change.

To specify the name of the node in the monitorable object tree that
the object represents, invoke the object's setName method.
In the invocation of the setName method, pass a string
that contains the name of the node as a parameter to the method.

The object that represents a statistic must also provide methods for
computing the statistic from event data.

The org.glassfish.flashlight.statistics package provides
the following utility classes to gather and compute statistics data:

Average

Provides averages.

Counter

Provides a counter that a class can use to maintain count.

TimeStats

Provides timing information in seconds.

TimeStatsMillis

Provides timing information in milliseconds.

TimeStatsNanos

Provides timing information in nanoseconds.

Note –

The classes in the org.glassfish.flashlight.statistics package
are unstable interfaces and are subject to change.

The org.glassfish.flashlight.statistics.factory package
provides a factory class for each utility class as shown in the following
table.

Utility Class

Factory Class

Average

AverageFactory

Counter

CounterFactory

TimeStats

TimeStatsFactory

TimeStatsMillis

TimeStatsFactory

TimeStatsNanos

TimeStatsFactory

Getting the server Node Object

The server node object is the parent of the TreeNode object that represents the component in the monitorable object
tree.

To get the server node object, invoke the get method of the org.glassfish.flashlight.MonitoringRuntimeDataRegistry class. In the invocation of the get method,
pass the string server as a parameter.

Adding an Object to the Tree

To add an object to the tree, invoke the addChild method
of the object's parent object. In the invocation of the addChild method, pass the TreeNode object
that you are adding as a parameter.

The parent object depends on whether the object represents an add-on
component or a statistic:

If the object represents an add-on component, the parent is
the server node object.

If the object represents a statistic, the parent is the TreeNode object that represents the add-on component.

Dotted Names for an Add-On Component's Statistics

The Enterprise Server administrative commands get(1), list(1),
and set(1) locate
a statistic through the dotted name of the statistic. The dotted name of a
statistic for an add-on component is determined from the names of the TreeNode objects that represent the statistic and the component
in the monitorable object tree as follows:

server.componenent-treenode-name.statistic-treenode-name

componenent-treenode-name

The name of the TreeNode object that
represents the component in the monitorable object tree. This name is passed
In the invocation of the createTreeNode method that
creates the object. For more information, see Creating a TreeNode Object to Represent a Component.

Example of Adding Statistics for a Component to the
Monitorable Object Tree

Example 5–6 Adding Statistics for a Component to the Monitorable
Object Tree

This example shows the code for adding the totaltransactioncount statistic
to the monitorable object tree. To add this statistic, objects are added to
the monitorable object tree as follows:

The component that is represented by the class TransactionManagerImpl is added as a child of the server node of
the tree. The name of the node is tx. The category is transactions. The dotted name of the monitorable object that represents
the component is server.tx.

The totaltransactioncount statistic is
added as a child of the tx node of the tree. The dotted
name of the monitorable object that represents the statistic is server.tx.totaltransactioncount.