10.2. Using Resource Proxies
ProxyFactory to interact with the remote and domain API.
ProxyFactory is available to the JBoss ON CLI in interactive mode or when using a script file. It is also available to server scripts, such as scripts used for alerting.
ProxyFactory gets information about a resource, which is identified in the getResource() method with the resource's ID number.
ProxyFactory can return a complete summary of information about the specified resource, such as its current monitoring data and traits, resource name, available metrics, available operations, content information, and child inventory, all dependent on the resource type. For example:
rhqadmin@localhost:7080$ ProxyFactory.getResource(10001)
ResourceClientProxy_$$_javassist_0:
OSName: Linux
OSVersion: 2.6.32-220.4.1.el6.x86_64
architecture: x86_64
children:
contentTypes: {rpm=RPM File}
createdDate: Mon Feb 06 11:24:50 EST 2012
description: Linux Operating System
distributionName: Red Hat Enterprise Linux Server
distributionVersion: release 6.2 (Santiago)
freeMemory: 16.7GB
freeSwapSpace: 25.6GB
handler:
hostname: server.example.com
id: 10001
idle: 70.8%
measurements: [Wait Load, Used Memory, System Load, Distribution Version, Total Memory, OS Name, Free Memory, Hostname, Architecture, Distribution Name, Idle, Total Swap Space, Used Swap Space, User Load, OS Version, Free Swap Space]
modifiedDate: Mon Feb 06 11:24:50 EST 2012
name: server.example.com
operations: [viewProcessList, cleanYumMetadataCache, manualAutodiscovery]
pluginConfiguration:
pluginConfigurationDefinition: ConfigurationDefinition[xml:id=10009, name=Linux]
resourceType: Linux
systemLoad: 0.0%
totalMemory: 23.5GB
totalSwapSpace: 25.6GB
usedMemory: 6.8GB
usedSwapSpace: 0.0B
userLoad: 15.8%
version: Linux 2.6.32-220.4.1.el6.x86_64
waitLoad: 0.0%ProxyFactory creates a resource proxy object.
Example 10.3. Defining a Platform Proxy Resource
var rhelServerOne = ProxyFactory.getResource(10001)
- Viewing basic information about the resource, such as its children
- Getting measurement information
- Running operations
- Changing resource and plug-in configuration
- Updating and retrieving content
Example 10.4. Viewing a Resource's Children
ProxyFactory has a method for all proxy objects, children, which lists all of the children for the proxy resource.
var rhelServerOne = ProxyFactory.getResource(10001) rhqadmin@localhost:7080$ platform.children Array of org.rhq.bindings.client.ResourceClientProxy [10027] Bundle Handler - Ant (Ant Bundle Handler::AntBundlePlugin) [10026] CPU 6 (CPU::Platforms) [10025] CPU 0 (CPU::Platforms) [10024] CPU 5 (CPU::Platforms) [10023] CPU 1 (CPU::Platforms) [10022] CPU 4 (CPU::Platforms) [10021] CPU 2 (CPU::Platforms) [10020] CPU 3 (CPU::Platforms) [10019] CPU 7 (CPU::Platforms) [10018] /boot (File System::Platforms) [10017] / (File System::Platforms) [10016] /dev/shm (File System::Platforms) [10015] /home (File System::Platforms) [10014] eth1 (Network Adapter::Platforms) [10013] eth2 (Network Adapter::Platforms) [10012] eth0 (Network Adapter::Platforms) [10011] lo (Network Adapter::Platforms) [10004] postgres (Postgres Server::Postgres) [10003] AS server.example.com RHQ Server (JBossAS Server::JBossAS) [10002] RHQ Agent (RHQ Agent::RHQAgent)
Example 10.5. Viewing Resource Metrics
ProxyFactory provides a set of shortcut metrics for each individual measurement for a resource type. This corresponds to the findLiveData() method in the remote API, but it is much easier to get monitoring information quickly and it is simpler to identify what metrics are available.
var jbossas = ProxyFactory.getResource(14832)
rhqadmin@localhost:7080$ jbossas.JVMTotalMemory
Measurement:
name: JVM Total Memory
displayValue: 995.3MB
description: The total amount of memory currently available in the app server JVM for current and fut...measurements method:
var rhelServerOne = ProxyFactory.getResource(10001) rhqadmin@localhost:7080$ rhelServerOne.measurements Array of org.rhq.bindings.client.ResourceClientProxy$Measurement name displayValue description ----------------------------------------------------------------------------------------------------------------------- Wait Load 0.0% Percentage of all CPUs waiting on I/O Used Memory 6.3GB The total used system memory System Load 0.0% Percentage of all CPUs running in system mode Distribution Version release 6.2 (Santiago) version of the Linux distribution Total Memory 31.4GB The total system memory OS Name Linux Name that the operating system is known as Free Memory 25.2GB The total free system memory Hostname server.example.com Name that this platform is known as Architecture x86_64 Hardware architecture of the platform Distribution Name Red Hat Enterprise Linux Server name of the Linux distribution Idle 92.6% Idle percentage of all CPUs Total Swap Space 33.6GB The total system swap Used Swap Space 0.0B The total used system swap User Load 16.7% Percentage of all CPUs running in user mode OS Version 2.6.32-220.4.2.el6.x86_64 Version of the operating system Free Swap Space 33.6GB The total free system swap 16 rows
Example 10.6. Running Operations on a Proxy
ProxyFactory has a shortcut method for every operation available for a resource.
var rhelServerOne = ProxyFactory.getResource(10001) rhqadmin@localhost:7080$ rhelServerOne.operations Array of org.rhq.bindings.client.ResourceClientProxy$Operation name description ----------------------------------------------------------------------------------------------------------------------- viewProcessList View running processes on this system cleanYumMetadataCache Deletes all cached package metadata manualAutodiscovery Run an immediate discovery to search for resources 3 rows
rhqadmin@localhost:7080$ rhelServerOne.viewProcessList();
Invoking operation viewProcessList
Configuration [11951] - null
processList [305] {
pid name size userTime kernelTime
------------------------------------------------------------------------------------------------------------------
1 init 19865600 150 10050
....
26285 httpd 214618112 90 80
26286 httpd 214618112 90 80
26288 httpd 214618112 110 70
26289 httpd 214618112 90 80
27357 java 4734758912 1289650 373890
30458 postgres 218861568 1820 27440
30460 postgres 180985856 1210 5330
30462 postgres 218984448 13080 42200
30463 postgres 218861568 3970 26940
30464 postgres 219328512 10600 15320
30465 postgres 181407744 18680 78760
30482 httpd 185905152 1660 7520
32410 bash 108699648 0 10
32420 java 6024855552 3890240 669810
305 rows
}Example 10.7. Changing Configuration Properties
editResourceConfiguration() and editPluginConfiguration(), respectively — to edit those properties.
get*Configuration). For example, for the plug-in configuration:
var rhelServerOne = ProxyFactory.getResource(10001)
rhqadmin@localhost:7080$ rhelServerOne.getPluginConfiguration()
Configuration [10793] - null
metadataCacheTimeout = 1800
enableContentDiscovery = false
yumPort = 9080
enableInternalYumServer = false
logs [0] {
}edit*Configuration() method brings up a configuration wizard that goes through all of the properties individually and prompts to keep or change each value. The properties are even grouped according to the same organization that the JBoss ON web UI uses. For example:
rhqadmin@localhost:7080$ rhelServerOne.editPluginConfiguration(); Non-Grouped Properties: Group: Content enableContentDiscovery[false]: enableInternalYumServer[false]: yumPort[9080]: metadataCacheTimeout[1800]: Group: Event Logs [R]eview, [E]dit, Re[V]ert [S]ave or [C]ancel: ...
| Keys | Action |
|---|---|
| return | Selects the default or existing value for a property. |
| ctrl-d | The same as selecting the unset checkbox in the configuration UI. |
| ctrl-k | Exits the configuration wizard. |
| ctrl-e | Displays the help description for the current property. |
Example 10.8. Managing Content on Resources
var contentResource = ProxyFactory.getResource(14932)
contentResource.retrieveBackingContent("/resources/backup/original.war")updateBackingContent method and specify the filename with the path on the application server to put the content and the version number of the content. For example:
contentResource.updateBackingContent("/resources/current/new.war", "2.0")
Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.