looks like I have figured it out Davis, with all inspiration I have had through you , here is my version of it, keeping it very simple:
// Sample Javascript code for Wily Introscope
//
// Compute the Heap Used % metric based on the Heap Total and Heap In Use metrics
//
function execute(metricData,javascriptResultSetHelper)
{
// for each input agent, compute a calculated metric named
// "<metric>|<agentname>:Heap Used %" as
// that agent's "Math.round(Bytes in Use / Bytes Total *100)".
var i=0; // binding iterator
var defectvalueFound=0;
var totalTransFound=0;
var agentList = {}; // list of agents
var defectvalue = {}; // array of bytesTotal values by agent
var totalTrans = {}; // array of bytesUsed values by agent
var agentFrequency = {}; // array of frequency by agent
log.info("1-metricDATA is: " + metricData);
for(i=0; i < metricData.length; i++)
{
var metric = metricData[i].agentMetric.attributeURL;
var agent = metricData[i].agentName.processURL;
var value = metricData[i].timeslicedValue.value;
var frequency = metricData[i].frequency;
// add to agentList if we haven't seen the agent yet
if (agentList[agent] == null)
{
agentList[agent] = agent;
}
log.info("2-metricFound is: " + metric);
log.info("2-agentFound is: " + agent);
// put the value in the right array
if (metric.indexOf(":Total Availability Defects"))
{
defectvalueFound = value;
}
if (metric.indexOf(":Total Transactions"))
{
totalTransFound = value;
}
agentFrequency[agent] = frequency;
}
// set up metric name
var metricName = "SuperDomain|Custom Metric Host (Virtual)|Custom Metric Process (Virtual)|Custom Metric Agent (Virtual)" + "|TAAS|Availability:Application Availability (%)";
var frequency = agentFrequency[agent];
var AvailValue = 100;
// make sure we're not going to divide by zero
if (defectvalueFound > 0 && totalTransFound > 0)
{
// perform the math
AvailValue = Math.round((100-((defectValueFound / totalTransFound) * 100)));
}
// add the calculated value to the result set
javascriptResultSetHelper.addMetric(metricName,
AvailValue,
javascriptResultSetHelper.kIntegerPercentage,
frequency);
// return the result set
return javascriptResultSetHelper;
}
// Tell the EM what agents we should match against
function getAgentRegex() {
return "Custom(.*)";
}
// Tell the EM what agent metrics we should match against
function getMetricRegex()
{
return ".*Availability.*";
}
// must return a multiple of default system frequency (currently 15 seconds)
function getFrequency()
{
return 15;
}
// Return false if the script should not run on the MOM.
// Scripts that create metrics on agents other than the Custom Metric Agent
// should not run on the MOM because the agents exist only in the Collectors.
// Default is true.
function runOnMOM()
{
return true;
}