org.rhq.enterprise.agent
Class AgentManagement

java.lang.Object
  extended by org.rhq.enterprise.agent.AgentManagement
All Implemented Interfaces:
MBeanRegistration, AgentManagementMBean

public class AgentManagement
extends Object
implements AgentManagementMBean, MBeanRegistration

This is the management layer for the agent. This is the MBean that is used to manage the agent itself. It emits the agent's metric data.

Author:
John Mazzitelli

Field Summary
static ObjectName singletonObjectName
           
 
Fields inherited from interface org.rhq.enterprise.agent.AgentManagementMBean
BASE_OBJECT_NAME, JMX_DOMAIN, KEY_NAME, PLUGIN_INFO_MD5, PLUGIN_INFO_NAME, PLUGIN_INFO_PATH, PLUGIN_INFO_SIZE, PLUGIN_INFO_TIMESTAMP
 
Constructor Summary
AgentManagement(AgentMain agent)
          Constructor for AgentManagement.
 
Method Summary
 void downloadLatestFailoverList()
          Tells the agent to download an updated server failover list.
 OperationResult executeAvailabilityScan(Boolean changesOnly)
          Asks the agent's plugin container to execute an availability scan and returns the results.
 String executePromptCommand(String command)
          Executes an agent prompt command.
 Properties getAgentConfiguration()
          Returns the entire set of agent configuration preferences.
 String getAgentHomeDirectory()
          Returns the directory that is considered the "agent home" (i.e.
 long getAgentServerClockDifference()
          Returns the number of milliseconds this agent thinks its clock is ahead or behind from its server's clock.
 long getAverageExecutionTimeReceived()
           
 long getAverageExecutionTimeSent()
           
 long getCurrentTime()
          Returns the current time, as it is known to the agent.
 int getJVMActiveThreads()
          Returns the number of currently active threads in the agent's JVM.
 long getJVMFreeMemory()
          Returns the agent JVM's free memory as reported by Runtime.getRuntime().freeMemory().
 long getJVMTotalMemory()
          Returns the agent JVM's total memory as reported by Runtime.getRuntime().totalMemory().
 MBeanServer getMBeanServer()
          Returns the MBeanServer where this MBean is registered; null if this MBean is not registered.
 int getNumberAgentRestarts()
          Returns the number of times the agent has been restarted for the entire lifetime of the agent's JVM.
 long getNumberCommandsActiveSent()
           
 long getNumberCommandsInQueue()
           
 long getNumberCommandsSpooled()
           
 long getNumberFailedCommandsReceived()
           
 long getNumberFailedCommandsSent()
           
 long getNumberSuccessfulCommandsReceived()
           
 long getNumberSuccessfulCommandsSent()
           
 long getNumberTotalCommandsReceived()
           
 long getNumberTotalCommandsSent()
          Combines the number of successful and failed commands sent.
 ObjectName getObjectName()
          This is the name that the MBean is registered under.
 String getReasonForLastRestart()
          Returns the code that indicates why the agent was last restarted.
 long getUptime()
          Returns the number of seconds the agent has been started - this resets everytime the agent is shutdown.
 String getVersion()
          Returns the agent's version string.
 boolean isSending()
           
 void mergeIntoAgentConfiguration(Properties config)
          The given set of agent configuration preferences (in the form of name/value pairs in a Properties object) is added to the current set of agent configuration preferences.
 void postDeregister()
           
 void postRegister(Boolean registrationDone)
           
 void preDeregister()
           
 ObjectName preRegister(MBeanServer server, ObjectName name)
           
 void removeFromAgentConfiguration(List<String> preferenceNames)
          Given the names of preferences, this will remove those preference settings from the agent configuration.
 void restart()
          This will perform an agent hot-restart.
 void restartPluginContainer()
          This will shutdown then immediately restart the agent's internal plugin container.
 OperationResult retrieveAllPluginInfo()
          Returns information on all currently deployed plugins.
 String retrieveCurrentDateTime(String timeZone)
          Returns a string of the agent's current date/time, formatted with the given time zone.
 OperationResult retrievePluginInfo(String pluginName)
          Returns information on the given plugin.
 void setDebugMode(Boolean enabled, Boolean traceMessaging)
          Turns on or off debug mode, which makes the agent log more verbose with debug messages.
 void shutdown()
          This will shutdown the agent's communications layer and the plugin container.
 void switchToServer(String server)
           
 void updatePlugins()
          This will tell the agent to update its plugins.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

singletonObjectName

public static ObjectName singletonObjectName
Constructor Detail

AgentManagement

public AgentManagement(AgentMain agent)
Constructor for AgentManagement.

Parameters:
agent - the agent to be monitored
Method Detail

switchToServer

public void switchToServer(String server)
Specified by:
switchToServer in interface AgentManagementMBean

restart

public void restart()
Description copied from interface: AgentManagementMBean
This will perform an agent hot-restart. The agent will be AgentManagementMBean.shutdown() and then immediately started again. This is usually called after a client has changed some configuration settings.

The actual restart is performed asynchronously. The caller has just a few seconds after this method returns before it takes effect.

Specified by:
restart in interface AgentManagementMBean

shutdown

public void shutdown()
Description copied from interface: AgentManagementMBean
This will shutdown the agent's communications layer and the plugin container. If the agent is in daemon mode, the agent's VM will die. Once this method is called, this management interface will no longer be available via JMX and the agent will no longer be able to process incoming commands or send outgoing commands.

The actual shutdown is performed asynchronously. The caller has just a few seconds after this method returns before it takes effect.

Specified by:
shutdown in interface AgentManagementMBean

downloadLatestFailoverList

public void downloadLatestFailoverList()
Description copied from interface: AgentManagementMBean
Tells the agent to download an updated server failover list. This will also check to make sure the agent is pointing to its primary server as found in the new failover list and, if not, will attempt to switch to the primary server now.

Specified by:
downloadLatestFailoverList in interface AgentManagementMBean

updatePlugins

public void updatePlugins()
Description copied from interface: AgentManagementMBean
This will tell the agent to update its plugins. If the JON Server is up and the agent has detected it, this will immediately pull down the updated plugins. If the JON Server is down, this will schedule the agent to pull down the plugins as soon as the JON Server comes back up.

After the plugins are updated, the plugin container will immediately be restarted.

The actual PC restart is performed asynchronously. The caller has just a few seconds after this method returns before it takes effect.

Specified by:
updatePlugins in interface AgentManagementMBean

retrieveAllPluginInfo

public OperationResult retrieveAllPluginInfo()
Description copied from interface: AgentManagementMBean
Returns information on all currently deployed plugins. The configuration will contain one PropertyMap for each plugin. The name of the map will be the plugin name. Each map will have the key/value pairs where the keys are PLUGIN_INFO_xxx.

Specified by:
retrieveAllPluginInfo in interface AgentManagementMBean
Returns:
information on all deployed plugins

retrievePluginInfo

public OperationResult retrievePluginInfo(String pluginName)
Description copied from interface: AgentManagementMBean
Returns information on the given plugin. The configuration will contain simple properties where the names are defined by PLUGIN_INFO_xxx.

Specified by:
retrievePluginInfo in interface AgentManagementMBean
Parameters:
pluginName - the plugin whose information is to be returned
Returns:
the plugin information

restartPluginContainer

public void restartPluginContainer()
Description copied from interface: AgentManagementMBean
This will shutdown then immediately restart the agent's internal plugin container. The plugin container manages all plugins and their lifecycles. This is usually called after a client has updated the plugins. Restarting the plugin container forces it to load in newly updated plugins.

The actual restart is performed asynchronously. The caller has just a few seconds after this method returns before it takes effect.

Specified by:
restartPluginContainer in interface AgentManagementMBean
See Also:
AgentManagementMBean.updatePlugins()

executeAvailabilityScan

public OperationResult executeAvailabilityScan(Boolean changesOnly)
Description copied from interface: AgentManagementMBean
Asks the agent's plugin container to execute an availability scan and returns the results. See DiscoveryAgentService.executeAvailabilityScanImmediately(boolean) for the semantics of this call.

Specified by:
executeAvailabilityScan in interface AgentManagementMBean
Parameters:
changesOnly - if true, only report those availabilities that have changed
Returns:
the report in an OperationResult object

getVersion

public String getVersion()
Description copied from interface: AgentManagementMBean
Returns the agent's version string. This does not necessarily help identify the versions of the plugins, since each plugin may have been updated from the JON Server since the initial installation of the agent.

Specified by:
getVersion in interface AgentManagementMBean
Returns:
identifies the version of the agent.

getCurrentTime

public long getCurrentTime()
Description copied from interface: AgentManagementMBean
Returns the current time, as it is known to the agent. This can be used to determine if the agent's clock is skewed from some other clock (e.g. the JON Server). The returned value is the number of milliseconds since midnight, January 1, 1970 UTC (as per System.currentTimeMillis.

Specified by:
getCurrentTime in interface AgentManagementMBean
Returns:
current time, as it is known to the agent

retrieveCurrentDateTime

public String retrieveCurrentDateTime(String timeZone)
Description copied from interface: AgentManagementMBean
Returns a string of the agent's current date/time, formatted with the given time zone. If the given time zone is null or empty string, the agent's local time zone will be used. If the given time zone is unknown, GMT will be the default. timeZonecan be either an abbreviation such as "PST", a full name such as "America/Los_Angeles", or a custom ID such as "GMT-8:00". Note that the support of abbreviations is for JDK 1.1.x compatibility only and full names should be used.

Specified by:
retrieveCurrentDateTime in interface AgentManagementMBean
Parameters:
timeZone - the time zone to display the date/time in
Returns:
the agent's current date/time
See Also:
TimeZone.getTimeZone(String)

setDebugMode

public void setDebugMode(Boolean enabled,
                         Boolean traceMessaging)
                  throws ExecutionException
Description copied from interface: AgentManagementMBean
Turns on or off debug mode, which makes the agent log more verbose with debug messages. This will also be able to optionally turn on and off messaging trace, which lets you debug the messaging between server and agent. If the enabled flag is false, traceMessaging is ignored (i.e. all debug will be disabled, including message tracing).

Specified by:
setDebugMode in interface AgentManagementMBean
Parameters:
enabled - enable debug mode
traceMessaging - if true, message tracing will be enabled unless enabled is false
Throws:
ExecutionException - if failed to change the debug mode

executePromptCommand

public String executePromptCommand(String command)
                            throws ExecutionException
Description copied from interface: AgentManagementMBean
Executes an agent prompt command. The given command is the prompt command plus any additional command arguments, separated by spaces (just as if you typed the command in the console window). The results will be a string that contains the text that you would have seen in the console output had the prompt command been executed from the console.

Specified by:
executePromptCommand in interface AgentManagementMBean
Parameters:
command - the command to execute along with any command line arguments.
Returns:
the output results of the executed prompt command
Throws:
ExecutionException - if the prompt command threw an exception, this method will throw an exception whose message is the output text that was written by the prompt command up until the error occurred. The cause of the thrown exception will be the actual exception thrown by the prompt command. This way you can see what the prompt command output was as well as the exception that occurred.

getAgentHomeDirectory

public String getAgentHomeDirectory()
Description copied from interface: AgentManagementMBean
Returns the directory that is considered the "agent home" (i.e. the directory where the agent is installed).

Specified by:
getAgentHomeDirectory in interface AgentManagementMBean
Returns:
agent home directory

getNumberAgentRestarts

public int getNumberAgentRestarts()
Description copied from interface: AgentManagementMBean
Returns the number of times the agent has been restarted for the entire lifetime of the agent's JVM. Reasons for a restart can include the execution of the agent plugin's "restart" operation or the VM Health Check detected a critical problem and restarted the agent automatically. To find out why the agent was last restarted, see AgentManagementMBean.getReasonForLastRestart().

Specified by:
getNumberAgentRestarts in interface AgentManagementMBean
Returns:
number of agent restarts that have occured

getReasonForLastRestart

public String getReasonForLastRestart()
Description copied from interface: AgentManagementMBean
Returns the code that indicates why the agent was last restarted.

Specified by:
getReasonForLastRestart in interface AgentManagementMBean
Returns:
restart code

getAgentServerClockDifference

public long getAgentServerClockDifference()
Description copied from interface: AgentManagementMBean
Returns the number of milliseconds this agent thinks its clock is ahead or behind from its server's clock. A positive value means the agent clock is ahead.

Specified by:
getAgentServerClockDifference in interface AgentManagementMBean
Returns:
time the agent-server clock difference

getUptime

public long getUptime()
Description copied from interface: AgentManagementMBean
Returns the number of seconds the agent has been started - this resets everytime the agent is shutdown. This time does not necessarily mean the total time the agent's VM has been running (since the agent may have been shutdown and restarted without the VM ever coming down).

Specified by:
getUptime in interface AgentManagementMBean
Returns:
number of seconds since the agent has been started

getNumberSuccessfulCommandsReceived

public long getNumberSuccessfulCommandsReceived()
Specified by:
getNumberSuccessfulCommandsReceived in interface AgentManagementMBean
See Also:
ServiceContainerMetricsMBean.getNumberSuccessfulCommandsReceived()

getNumberFailedCommandsReceived

public long getNumberFailedCommandsReceived()
Specified by:
getNumberFailedCommandsReceived in interface AgentManagementMBean
See Also:
ServiceContainerMetricsMBean.getNumberFailedCommandsReceived()

getNumberTotalCommandsReceived

public long getNumberTotalCommandsReceived()
Specified by:
getNumberTotalCommandsReceived in interface AgentManagementMBean
See Also:
ServiceContainerMetricsMBean.getNumberTotalCommandsReceived()

getAverageExecutionTimeReceived

public long getAverageExecutionTimeReceived()
Specified by:
getAverageExecutionTimeReceived in interface AgentManagementMBean
See Also:
ServiceContainerMetricsMBean#getAverageExecutionTime()

getAverageExecutionTimeSent

public long getAverageExecutionTimeSent()
Specified by:
getAverageExecutionTimeSent in interface AgentManagementMBean
See Also:
ClientCommandSenderMetrics.getAverageExecutionTimeSent()

getNumberSuccessfulCommandsSent

public long getNumberSuccessfulCommandsSent()
Specified by:
getNumberSuccessfulCommandsSent in interface AgentManagementMBean
See Also:
ClientCommandSenderMetrics.getNumberSuccessfulCommandsSent()

getNumberFailedCommandsSent

public long getNumberFailedCommandsSent()
Specified by:
getNumberFailedCommandsSent in interface AgentManagementMBean
See Also:
ClientCommandSenderMetrics.getNumberFailedCommandsSent()

getNumberTotalCommandsSent

public long getNumberTotalCommandsSent()
Description copied from interface: AgentManagementMBean
Combines the number of successful and failed commands sent.

Specified by:
getNumberTotalCommandsSent in interface AgentManagementMBean
See Also:
ClientCommandSenderMetrics.getNumberSuccessfulCommandsSent(), ClientCommandSenderMetrics.getNumberFailedCommandsSent()

getNumberCommandsActiveSent

public long getNumberCommandsActiveSent()
Specified by:
getNumberCommandsActiveSent in interface AgentManagementMBean
See Also:
ClientCommandSenderMetrics.getNumberCommandsActive()

getNumberCommandsInQueue

public long getNumberCommandsInQueue()
Specified by:
getNumberCommandsInQueue in interface AgentManagementMBean
See Also:
ClientCommandSenderMetrics.getNumberCommandsInQueue()

getNumberCommandsSpooled

public long getNumberCommandsSpooled()
Specified by:
getNumberCommandsSpooled in interface AgentManagementMBean
See Also:
ClientCommandSenderMetrics.getNumberCommandsSpooled()

isSending

public boolean isSending()
Specified by:
isSending in interface AgentManagementMBean
See Also:
ClientCommandSenderMetrics.isSending()

getJVMFreeMemory

public long getJVMFreeMemory()
Description copied from interface: AgentManagementMBean
Returns the agent JVM's free memory as reported by Runtime.getRuntime().freeMemory().

Specified by:
getJVMFreeMemory in interface AgentManagementMBean
Returns:
free memory in bytes

getJVMTotalMemory

public long getJVMTotalMemory()
Description copied from interface: AgentManagementMBean
Returns the agent JVM's total memory as reported by Runtime.getRuntime().totalMemory().

Specified by:
getJVMTotalMemory in interface AgentManagementMBean
Returns:
total memory in bytes

getJVMActiveThreads

public int getJVMActiveThreads()
Description copied from interface: AgentManagementMBean
Returns the number of currently active threads in the agent's JVM.

Specified by:
getJVMActiveThreads in interface AgentManagementMBean
Returns:
number of all active threads

getAgentConfiguration

public Properties getAgentConfiguration()
Description copied from interface: AgentManagementMBean
Returns the entire set of agent configuration preferences.

Specified by:
getAgentConfiguration in interface AgentManagementMBean
Returns:
agent configuration preferences

mergeIntoAgentConfiguration

public void mergeIntoAgentConfiguration(Properties config)
Description copied from interface: AgentManagementMBean
The given set of agent configuration preferences (in the form of name/value pairs in a Properties object) is added to the current set of agent configuration preferences. Those preferences found in config that already exist in the current agent configuration will override the old values in the current agent configuration. Those preferences found in config but do not exist yet in the current agent configuration are added to the agent configuration. If a preference exists in the current configuration but is not found in config, then that preference is left as-is.

Changing the agent configuration usually requires the agent to be restarted in order for the new settings to be picked up.

Specified by:
mergeIntoAgentConfiguration in interface AgentManagementMBean
Parameters:
config - new agent configuration preferences

removeFromAgentConfiguration

public void removeFromAgentConfiguration(List<String> preferenceNames)
Description copied from interface: AgentManagementMBean
Given the names of preferences, this will remove those preference settings from the agent configuration. This will effectively force that preferences to fallback to their built-in defaults.

Specified by:
removeFromAgentConfiguration in interface AgentManagementMBean
Parameters:
preferenceNames - the preferences to remove from the agent configuration

getMBeanServer

public MBeanServer getMBeanServer()
Returns the MBeanServer where this MBean is registered; null if this MBean is not registered.

Returns:
the hosting MBeanServer

getObjectName

public ObjectName getObjectName()
This is the name that the MBean is registered under.

Returns:
mbean name

preRegister

public ObjectName preRegister(MBeanServer server,
                              ObjectName name)
                       throws Exception
Specified by:
preRegister in interface MBeanRegistration
Throws:
Exception
See Also:
MBeanRegistration.preRegister(MBeanServer, ObjectName)

postRegister

public void postRegister(Boolean registrationDone)
Specified by:
postRegister in interface MBeanRegistration
See Also:
MBeanRegistration.postRegister(Boolean)

postDeregister

public void postDeregister()
Specified by:
postDeregister in interface MBeanRegistration
See Also:
MBeanRegistration.postDeregister()

preDeregister

public void preDeregister()
                   throws Exception
Specified by:
preDeregister in interface MBeanRegistration
Throws:
Exception
See Also:
MBeanRegistration.preDeregister()


Copyright © 2008-2011 Red Hat, Inc.. All Rights Reserved.