public interface StatsManagementMBean
The StatsManagementMBean provides methods that allow clients to determine what statistical parameter sets the Rhino cluster is capable of providing and an API for extracting statistical information.
Client applications extract statistical information from Rhino using the session API provided by this MBean. With the session
API client create one or more sessions each with an instance of the StatsManagementMBean running in a Rhino cluster (see
createSession()
.
Client applications may specify the counters and frequency distributions they are interested in by subscribing them to their session.
The API provides two ways for clients to retrieve subscribed statistical data, the mode of delivery used depends on the
method used to create the session. createSession()
creates a JMX session where statistics are delivered to the client
when the client calls getAccumulatedSamples(long)
. Sessions created using createDirectSession()
do not
accumulate samples for clients to retrieve over JMX, instead they establish a socket connection directly from each Rhino node to
the client and send statistical data using a proprietary protocol.
For general usage the JMX delivery method is recommended.
To use the session API to retrieve statistics, a client must follow the following steps:
createSession()
.subscribeCounter(long, int, String, String, SubscriptionMode)
and subscribeSample(long, int, String, String, SubscriptionMode, int, int)
,
store the returned subscription id's for each.startCollecting(long, long)
.getAccumulatedSamples(long)
, use the saved subscription id's
to map each element in the snapshot to a subscribed statistic.The following code snippet gives an example of reading the "active" statistic from the "Activities" parameter set and the "activeRootSbbs" statistic from the "Services" parameter set. The client will have Rhino take a snapshot of the counters every 1 second, and download the snapshots from Rhino every 5 seconds:
DateFormat df = new SimpleDateFormat("yyyy.MM.dd 'at' HH:mm:ss z"); ObjectName statsManagement = new ObjectName(StatsManagementMBean.OBJECT_NAME); StatsManagementMBean mbean = (StatsManagementMBean) getMBeanProxy(statsManagement, StatsManagementMBean.class, false); long sessionId = mbean.createSession(); int nodeId = 0; // "all nodes" int activeRootSbbs = mbean.subscribeCounter(sessionId, nodeId, "Services", "activeRootSbbs", SubscriptionMode.SIMPLE_GAUGE); int activeActivities = mbean.subscribeCounter(sessionId, nodeId, "Activities", "active", SubscriptionMode.SIMPLE_GAUGE); // rhino will begin gathering samples every 1 sec mbean.startCollecting(sessionId, 1000); while (true) { Thread.sleep(5000); Snapshot[] snapshots = mbean.getAccumulatedSamples(sessionId); for (int i = 0; i < snapshots.length; i++) { Snapshot snapshot = snapshots[i]; String date = df.format(new Date(snapshot.getTimestamp())); int[] subsIds = snapshot.getSubscriptionIds(); for (int j = 0; j < subsIds.length; j++) { final int subsId = subsIds[j]; if (subsId == activeActivities) System.out.println(date + ": active activities="+snapshot.getData()[j][0]); else if (subsId == activeRootSbbs) System.out.println(date + ": active SBBs="+snapshot.getData()[j][0]); else System.err.println("Unknown subscription id: "+subsId); } } }
Modifier and Type | Interface and Description |
---|---|
static class |
StatsManagementMBean.StatsMessageConstants |
Modifier and Type | Field and Description |
---|---|
static String |
OBJECT_NAME |
Modifier and Type | Method and Description |
---|---|
com.opencloud.rhino.monitoring.stats.session.DirectSessionState |
createDirectSession()
Create a new statistics sampling session with direct delivery of statistics over a socket connection.
|
long |
createSession()
Create a new statistics sampling session.
|
Snapshot[] |
getAccumulatedSamples(long sessionId)
Get all accumulated snapshots for a session.
|
int[] |
getMembers()
Returns an array of node ids representing the current cluster membership.
|
String[] |
getParameterSetNames()
Returns all known parameter set names.
|
String[] |
getParameterSetNames(String parameterSetName)
Returns the parameter set names of all parameter sets belonging to a specified parameter set.
|
String |
getParameterSetType(String parameterSetName)
Returns the type of a parameter set.
|
CompositeData |
getParameterSetTypeDescription(String type)
Returns a tabular data representing the parameter set type description.
|
TabularData |
getParameterSetTypeDescriptions()
Returns a tabular data containing the descriptions for the available parameter set types.
|
TabularData |
getParameterSetTypeMappings()
Returns a tabular data containing mappings from parameter sets to parameter set types.
|
String[] |
getParameterSetTypes()
Returns the parameter set types supported by the server.
|
String[] |
getRootParameterSetNames()
Returns the names of all root parameter sets.
|
void |
removeSession(long sessionId)
Remove a previously created statistics session.
|
void |
startCollecting(long sessionId,
long pollingPeriod)
Start collecting statistics for a session.
|
void |
stopCollecting(long sessionId)
Stop collecting statistics for a session.
|
int |
subscribeCounter(long sessionId,
int nodeid,
String parameterSetName,
String statisticName,
SubscriptionMode mode)
Subscribe a counter type statistic to a session.
|
int |
subscribeSample(long sessionId,
int nodeid,
String parameterSetName,
String statisticName,
SubscriptionMode mode,
int generations,
int rolloverPeriod)
Subscribe a sample type statistic to a session.
|
void |
unsubscribe(long sessionId,
int subscriptionId)
Remove a subscription from a session.
|
static final String OBJECT_NAME
int[] getMembers()
String[] getParameterSetTypes()
String[] getRootParameterSetNames()
String[] getParameterSetNames()
String[] getParameterSetNames(String parameterSetName) throws UnknownStatsParameterSetException
parameterSetName
- parameter set name.UnknownStatsParameterSetException
- if parameterSetName
does not
identify a known parameter set.String getParameterSetType(String parameterSetName) throws UnknownStatsParameterSetException
parameterSetName
- the name of the parameter set.null
if the parameter set has
no defined type.UnknownStatsParameterSetException
- if parameterSetName
does not
identify a known parameter set.TabularData getParameterSetTypeMappings() throws ManagementException
ManagementException
- if an internal error occurs.CompositeData getParameterSetTypeDescription(String type) throws ManagementException, UnknownStatsParameterTypeException
java.lang.Integer
java.lang.String
java.lang.String
java.lang.String
java.lang.String
java.lang.String
java.lang.String
java.lang.String
java.lang.String
java.lang.Boolean
java.lang.Boolean
type
- the name of a parameter set type returned by getParameterSetType(String)
or getParameterSetTypes()
.ManagementException
- if an internal error occurs.UnknownStatsParameterTypeException
- if the specified parameter set type does not exist.TabularData getParameterSetTypeDescriptions() throws ManagementException
getParameterSetTypeDescription(String)
method.ManagementException
- if an internal error occurs.long createSession() throws ManagementException
Clients using this method to create a session should use periodic calls to getAccumulatedSamples(long)
to
retrieve statistics.
ManagementException
- if an internal error occurs during session creationcom.opencloud.rhino.monitoring.stats.session.DirectSessionState createDirectSession() throws ManagementException
Clients using this method to create a session should not use periodic calls to getAccumulatedSamples(long)
to
retrieve statistics. Instead Rhino cluster members will connect directly to the clients published IP and port to
deliver the statistics over a proprietary protocol.
ManagementException
- if an internal error occurs during session creationvoid removeSession(long sessionId) throws NoSuchStatsSessionException, ManagementException
All subscriptions attached to the session will be removed. If the session is currently collecting statistics (ie.
startCollecting(long, long)
has been called), the collection timer will be stopped.
If sample type statistics are included in the session Rhino will stop collecting samples for those frequency distributions.
sessionId
- session id of the session to removeNoSuchStatsSessionException
- if the session id is invalid or the session has already been removedManagementException
- if an internal error occurs during session removalint subscribeCounter(long sessionId, int nodeid, String parameterSetName, String statisticName, SubscriptionMode mode) throws UnknownStatsParameterSetException, UnrecognizedStatisticException, NoSuchStatsSessionException, ManagementException
The counter type statistic will be added to the session's subscription list. If samples are being collected (ie.
startCollecting(long, long)
has been called), values for the counter subscription will start appearing
immediately in all subsequent snapshots.
sessionId
- session id of the session to subscribe the counter withnodeid
- node id of the cluster member from which to retrieve the counter, or the special node id 0
to get counter values from all nodesparameterSetName
- name of the parameter set containing the counterstatisticName
- name of the statistic from the parameter setmode
- a subscription mode from SubscriptionMode
- one of SIMPLE_COUNTER
, SIMPLE_GAUGE
,
DELTA_COUNTER
or PER_SECOND_COUNTER
.Snapshot
with the
correct valuesUnknownStatsParameterSetException
- if the parameter set does not existUnrecognizedStatisticException
- if the statistic name does not exist within the parameter setNoSuchStatsSessionException
- if the session id is invalid or the session has been removedManagementException
- if an internal error occurs processing the subscriptionint subscribeSample(long sessionId, int nodeid, String parameterSetName, String statisticName, SubscriptionMode mode, int generations, int rolloverPeriod) throws UnknownStatsParameterSetException, UnrecognizedStatisticException, NoSuchStatsSessionException, ManagementException
The sample type statistic will be added to the session's subscription list, and all Rhino nodes included in the subscription
(according to the nodeid
parameter) will begin building a frequency distribution for the samples.
If samples are being collected (ie.
startCollecting(long, long)
has been called) frequency distribution values for the sample subscription will start appearing
immediately in all subsequent snapshots
sessionId
- session id of the session to subscribe the sample statistic withnodeid
- node id of the cluster member from which to retrieve the counter, or the special node id 0
to get counter values from all nodesparameterSetName
- name of the parameter set containing the counterstatisticName
- name of the statistic from the parameter setmode
- a subscription mode from SubscriptionMode
- one of ROLLING_FREQUENCY_DISTRIBUTION
,
PERMANENT_FREQUENCY_DISTRIBUTION
or RESETTING_FREQUENCY_DISTRIBUTION
generations
- number of generations to keep (ignored unless mode is ROLLING_FREQUENCY_DISTRIBUTION
)rolloverPeriod
- rollover period for each generation (ignored unless mode is ROLLING_FREQUENCY_DISTRIBUTION
)Snapshot
with the
correct valuesUnknownStatsParameterSetException
- if the parameter set does not existUnrecognizedStatisticException
- if the statistic name does not exist within the parameter setNoSuchStatsSessionException
- if the session id is invalid or the session has been removedManagementException
- if an internal error occurs processing the subscriptionvoid unsubscribe(long sessionId, int subscriptionId) throws ManagementException, NoSuchStatsSessionException
The subscribed statistic will be removed from the session's subscription list. If samples are being collected (ie.
startCollecting(long, long)
has been called) the statistic will stop appearing in all subsequent snapshots.
If the statistic is a sample type statistic Rhino will stop collecting samples for it's frequency distribution.
sessionId
- session id of the session to unsubscribe fromsubscriptionId
- subscription id of the subscription to remove (must have been previously returned by
subscribeCounter(long, int, String, String, SubscriptionMode)
or subscribeSample(long, int, String, String, SubscriptionMode, int, int)
.ManagementException
- if an internal error occursNoSuchStatsSessionException
- if the session id is invalid or the session has been removedSnapshot[] getAccumulatedSamples(long sessionId) throws NoSuchStatsSessionException
When a session begins collecting snapshots startCollecting(long, long)
accumulated snapshots are stored
within session state on the Rhino node which owns the session (typically the node running the MBean server
used to create the session). Clients must periodically call getAccumulatedSamples
to extract all
stored snapshots. This method clears the list of stored snapshots so there is no need for clients to check for
duplicate or overlapping snapshots.
If the session is not currently collecting snapshots, or there are no snapshots available an empty array will be returned.
Clients should not call this method if the direct delivery mode of stats collection is in use (ie. the session
was created using createDirectSession()
.
sessionId
- session idSnapshot
NoSuchStatsSessionException
- if the session id is invalid or the session has been removedvoid startCollecting(long sessionId, long pollingPeriod) throws NoSuchStatsSessionException
A collection timer will be started on the session owning node (typically the node running the MBean server
used to create the session) with the specified pollingPeriod
and a new snapshot collected each
time the timer fires. What happens with the snapshot depends on how the session was created:
createSession()
new snapshots are simply appended to the snapshot list, where they
can be retrieved by clients using getAccumulatedSamples(long)
.createDirectSession()
new snapshot information is delivered directly to
clients by the originating nodes over a socket connection using a proprietary communication protocol.
Sessions that are collecting statistics will be timed out and removed if inactive for a period of time. A session
is considered inactive if it is currently collecting statistics and getAccumulatedSamples(long)
has not
been called for some time. The timeout period is calculated by Rhino's statistics manager and is the *greater* of:
stats-session-timer
from rhino-config.xml
)pollingPeriod
when collection is started by calling this method
Clients must take care to call getAccumulatedSamples(long)
frequently enough to avoid this timeout or
the session will be removed by Rhino and all state attached to the clients session will be lost.
Typically calling every 5 * pollingPeriod
milliseconds will be very safe.
Note that the above applies only to standard statistics sessions. Direct delivery sessions use a proprietary mechanism built into the rhino-stats client protocol to determine session liveness.
sessionId
- session idpollingPeriod
- desired time in milliseconds between snapshotsNoSuchStatsSessionException
- if the session id is invalid or the session has been removedvoid stopCollecting(long sessionId) throws NoSuchStatsSessionException
If the session is collecting statistics it's session timer will be cancelled. No session state is removed and any subscriptions and accumulated snapshots remain as part of the sessions state. Once this method is called on a session that is collecting statistics that session is no longer subject to removal due to timeout.
sessionId
- session idNoSuchStatsSessionException
- if the session id is invalid or the session has been removed