Example JON CLI script that retrieves live metrics for descendant resource from a specific ancestor

Solution Unverified - Updated -


  • Red Hat JBoss Operations Network (ON) 3.1
  • JBoss ON command-line interface (CLI)
  • Metrics from a resource that is two or more levels deep from a specific grand parent resource


  • How can I get the JVM memory usage metrics for a JBoss application server resource
  • Example of how to retrieve current metrics for a descendant resource


The following provides an example JBoss ON CLI script that can retrieve the live JVM memory metrics for all RHQ Server resources that are in inventory and have an availability state of UP:

 * To the extent possible under law, Red Hat, Inc. has dedicated all 
 * copyright to this software to the public domain worldwide, pursuant 
 * to the CC0 Public Domain Dedication. This software is distributed 
 * without any warranty.  
 * See <http://creativecommons.org/publicdomain/zero/1.0/>.

// get all the memory subsystem resources
var criteria = new ResourceCriteria();
criteria.addFilterResourceTypeName('VM Memory System');
criteria.addFilterName('Memory Subsystem');
var vmMemResources = ResourceManager.findResourcesByCriteria(criteria);

// get the AS resources we care about
var criteria = new ResourceCriteria();
criteria.addFilterResourceTypeName('JBossAS Server');
criteria.addFilterName('RHQ Server');
var asResources = ResourceManager.findResourcesByCriteria(criteria);

// search for the resource type to use in the metrics definition lookup
// in this example, we are limiting this to VM Memory System from the JBoss AS 4 plug-in
var resType = ResourceTypeManager.getResourceTypeByNameAndPlugin("VM Memory System", "JBossAS");

// search for the metric definitions
// this is using the resType defined above so scope is limited
var metricDefCriteria = MeasurementDefinitionCriteria();
var metricDefs = MeasurementDefinitionManager.findMeasurementDefinitionsByCriteria(metricDefCriteria);

// get live data
for (var asResCount = 0; asResCount < asResources.size(); asResCount++) { 
    var asResource = asResources.get(asResCount);
    // only for resource that are up
    if (asResource.getCurrentAvailability().getAvailabilityType() === AvailabilityType.UP) {
        var asResId = asResource.getId();
        // we have to iterate the memory resoruces to see which one belongs to this resource
        for (var memResCount = 0; memResCount < vmMemResources.size(); memResCount++) {
            var matched = false;
            // we have to traverse to the grand parent resource
            var memResource = vmMemResources.get(memResCount);
            var memResourceLineage = ResourceManager.findResourceLineage(memResource.getId());
            for (var ancestorCount = 0; ancestorCount < memResourceLineage.size(); ancestorCount++) {
                if (memResourceLineage.get(ancestorCount).getId() === asResId) {
                    matched = true;
                    // we break because we don't need to go through any more ancestors

            // the memResource belongs to the asResource so we need to get its metrics
            if (matched === true) {
                // for each metric definition
                var metricDefIds = [];
                for (var metricDefCount = 0; metricDefCount < metricDefs.size(); metricDefCount++) {
                var liveMetrics = MeasurementDataManager.findLiveData(memResource.getId(), metricDefIds);
                if (liveMetrics != null) {
                    var serverResourceName = asResource.getName();
                    var metricIterator = liveMetrics.iterator();
                    println("\"Name\",Timestampe,Value,\"Server Name\"");
                    while (metricIterator.hasNext()) {
                        var metric = metricIterator.next();
                        var metricName = metric.getName();
                        var metricTime = metric.getTimestamp();
                        var metricValue = metric.getValue();
                        println("\"" + metricName + "\"," + metricTime + "," + metricValue + ",\"" + serverResourceName + "\"");
                // we break because we don't need to go through any more memory subsystems for this resource

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.