HQU Get Metric Data Snippet
Description
This script gets a list of metric data points for resources of a certain type. It returns the result in XML. Useful for asking the question, _'What is the recent Bits Received for all my Cisco IOS resources?'
Works With
HQ 3.2.2 or higher
Running
Simply paste this script into the Groovy Console, and press execute.
Configuration
The best way to see what the valid resource types are, is to navigate find it in the 'Metric Defaults' section.
- Navigate to the Administration section
- Select Monitoring Defaults
Names of resource types are listed on the left-side.
Snippet
import org.hyperic.hq.hqu.rendit.util.HQUtil
import org.hyperic.hq.hqu.rendit.helpers.ResourceHelper
import groovy.xml.MarkupBuilder
def resourceType = 'JBoss 4.0 JMS Destination'
def overlord = HQUtil.overlord
def rhelp = new ResourceHelper(overlord)
def prototype = rhelp.findResourcePrototype(resourceType)
def resources = rhelp.findResourcesOfType(prototype)
def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
xml.resources() {
for (r in resources) {
xml.resource(name: r.name, id: r.id) {
for (metric in r.enabledMetrics) {
def metricData = metric.lastDataPoint
xml.metric(name: metric.template.name,
value: metricData.value,
time: metricData.timestamp)
}
}
}
}
writer.toString()
Related Files
- ResourceHelper.groovy - Locate resources, resource types, groups
- ResourceCategory.groovy - Extra methods on resources (createInstance)
- MetricCategory.groovy - Extra methods on Measurements