Pages

Tuesday, November 12, 2013

JON CLI Basics

JON ( JBoss Operations Network) is a very use full tool in monitoring , managing redhat Products. It can be use full in monitoring various resources like operating system metrics, JBboss , tomcat and also apache web servers. Many details regarding the under lying components can be obtained using the JON console.

JON can be exposed using its remote api provided. Clients can be coded to access the jon using the api. These APIs allow clients to access the server functionality — alerting, monitoring, managing inventory and resources, even agents.

EJB play a major role in defining JON system. They expose the services in different interfaces
1.web Interface
2.JON CLI ( Command Line Interface )

JBoss ON CLI can be downloaded and installed locally which uses Java and the remote API to support scripting and command line services for JON.

JON cli is stand alone java application which is based on java Scripting interface.

The JBoss Operations Network CLI itself is a Java shell the allows administrators to connect to the JBoss ON server over the command line. Essentially, the CLI is a script execution engine. It treats the JBoss ON API as if it was written in a scripting language, which makes it more convenient to manage the JBoss ON server.

The JBoss ON CLI is opened through a script, rhq-cli.sh|bat

Install the Command Line Tool
The Command line tool can be obtained in a zip form. here are the Steps to do that

Open the JBoss ON GUI - http://server.example.com:7080
Click the Administration link in the main menu.
Select the Downloads menu item.
Scroll to the Command Line Client Download section, and click Download Client Installer.
Save the .zip file into the directory where the CLI should be installed.
Unzip the packages.
unzip rhq-client-version.zip

This is downloaded from the JON GUI since Only the corresponding version of the CLI can be used to manage the JBoss ON server.

Running the JON CLI

:) [xk477@vx18d /upapps/wam/remote-scripts/rhq-remoting-cli-4.4.0.JON312GA/bin]$ ./rhq-cli.sh

RHQ Enterprise Remote CLI 4.4.0.JON312GA
unconnected$ login cliadmin password vx1324 7080
Remote server version is: 3.1.2.GA (2852293:bbe1c9b)
Login successful

Single Command Line

A single command can be passed to the CLI by using the -c. In this example, the server searches for and prints all supported resource types
[dwls999@vx181d bin]$ ./rhq-cli.sh -s vx1324 -u cliadmin -t 7080 -p password -c "pretty.print(ResourceTypeManager.findResourceTypesByCriteria(new ResourceTypeCriteria()))" > resource_types.txt

Executing a File
external files can also be executed by using the rhq-cli.sh Command. Open a File and Write a jon Cli script like,

println("Scanning All Tomcat Instances");
var criteria = ResourceCriteria();
criteria.addFilterResourceCategories([ResourceCategory.valueOf("SERVER")]);
criteria.addFilterPluginName("Tomcat");
var resources = ResourceManager.findResourcesByCriteria(criteria);
pretty.print(resources);


Save the Script , run the script using
./rhq-cli.sh -s vx1324 -u cliadmin -t 7080 -p devJasAdmin0 -f <Script Location>/<Script Name>

Variables
JON Cli provides various variables that help in our development of code.As 'java.lang.*” package is by default imported , JON cli also imports some of the packages.

Everything under the org.rhq.core.domain class is automatically imported, which makes it easier to use the CLI for managing resources, alerts, and other aspects of JBoss ON

Some of the variable include ,
criteria - provides a flexible framework for fine-tuned query operations.
Pretty - Provides for tabular-formatted printed and handles converting objects into a format suitable for display in the console.
ProxyFactory - Resource proxies are custom objects generated in the CLI that simplify interacting with the remote and domain APIs. Proxies are obtained through the ProxyFactory by calling getResource() and providing a resource identifier

Samples
Now we will write some of the basic snippets for starting the JON Cli,

Criteria-Based Searching
Criteria provides a flexible framework for fine-tuned query operations.If we need to search for some this ,we can use the Criteria.If we need to find out the available JBoss AS5 resources we can write all the commands in a file and execute or we can execute one by one like this

cliadmin@vx1324:7080$ var criteria = ResourceCriteria();

cliadmin@vx1324:7080$ criteria.addFilterResourceCategories([ResourceCategory.valueOf("SERVER")]);

cliadmin@vx1324:7080$ criteria.addFilterPluginName("JBossAS5");

cliadmin@vx1324:7080$ var resources = ResourceManager.findResourcesByCriteria(criteria);
cliadmin@vx1324:7080$ pretty.print(resources);

This will print the below details like,
id name version currentAvailabil resourceType
-------------------------------------------------------------------------------
26923 ESA-A1 EWP 5.0.0.GA UP JBossAS Server
71507 DSA-A1 EWP 5.0.0.GA UP JBossAS Server
26078 PSA-A1 EWP 5.0.0.GA UP JBossAS Server

Once we get the Id and various types of JBoss AS 5 resources we can use the ProxyFactory to get information about that specific resource

cliadmin@vx1324:7080$var rhelServerOne = ProxyFactory.getResource(81441)

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.

cliadmin@vx1324:7080$ pretty.print(rhelServerOne);
ResourceClientProxy_$$_javassist_0:
availability: ?
children:
contentTypes: {}
createdDate: Fri Jul 05 01:11:07 CDT 2013
description: JVM of the JBossAS
handler:
id: 81441
measurements: [Availability]
modifiedDate: Fri Jul 05 01:11:07 CDT 2013
name: JVM
operations: []
pluginConfiguration:
pluginConfigurationDefinition: ConfigurationDefinition[id=10248, name=JBoss AS JVM]
resourceType: JBoss AS JVM
version: 1.6.0_16


We can even fine tune this like,
cliadmin@vx1324:7080$ pretty.print(rhelServerOne.id)
81441.0

cliadmin@vx1324:7080$ pretty.print(rhelServerOne.version);
1.6.0_16

We can see all the supported Operations on a Resource using ,

cliadmin@vx1324:7080$var rhelServerOne = ProxyFactory.getResource(81441)
cliadmin@vx1324:7080$ Operations

cliadmin@vx1324:7080$ pretty.print(rhelServerOne.operations);
Array of org.rhq.bindings.client.ResourceClientProxy$Operation
name description
-------------------------------------------------------------------------------
setDebugMode Turns on or off debug mode, which causes the agent to
getInfoOnAllPlugins Retrieves information on all deployed plugins.
getCurrentDateTime Obtains the agent's current date/time.
executePromptCommand Executes an agent prompt command, just as if you invok
shutdownAgent Shuts down the agent's comm layer and plugin container
executeAvailabilityScan Runs an availability scan and returns a report of its
updateAllPlugins Tells the agent to update its plugins. This pulls new/
switchToServer Tell the agent to immediately switch to another server
downloadLatestFailoverList Tells the agent to download an updated server failover
getPluginInfo Retrieves information on a specific plugin.
restartAgent Shuts down the agent's comm layer and plugin container
restartPluginContainer Recycles the plugin container.
12 rows

Once the available Operations are obtained we can perform operations like,

cliadmin@vx1324:7080$var rhelServerOne = ProxyFactory.getResource(81441)
cliadmin@vx1324:7080$rhelServerOne.getInfoOnAllPlugins();
Invoking operation getInfoOnAllPlugins
.

cliadmin@vx1324:7080$ rhelServerOne.restartAgent();
Invoking operation restartAgent

cliadmin@vx1324:7080$ rhelServerOne.getPluginConfiguration();
Configuration [47084] - null
snapshotLogEnabled = true
snapshotDataEnabled = true
snapshotConfigEnabled = true
type = org.mc4j.ems.connection.support.metadata.InternalVMTypeDescriptor
connectorAddress = Local Connection
logEventSources [0] {
}

Write To a External Files
The Output of the script or the commands can be written to a external file using the exporter like

cliadmin@vx1324:7080$ var criteria = ResourceCriteria();
cliadmin@vx1324:7080$ criteria.addFilterResourceCategories([ResourceCategory.valueOf("SERVER")]);
cliadmin@vx1324:7080$ criteria.addFilterPluginName("JBossAS5");
cliadmin@vx1324:7080$ var resources = ResourceManager.findResourcesByCriteria(criteria);
cliadmin@vx1324:7080$ exporter.setTarget('raw', 'output.txt')
cliadmin@vx1324:7080$ exporter.write(resources)

or To CSV Files
exporter.setTarget('csv', 'output.csv')


More To Come , Happy Learning