Hi Arwin,
Thanks for attaching your script - this is the default (OOTB) JavaScript.
The snippet you've posted from your lower environment is doing the same check as the snipped I proposed to insert. This is checking the condition if the averageCPU metric that was calculated is greater than zero. If not, strange things can happen like the million-metrics (random numbers!) you've seen but only in case the input metrics go to zero, too. I've checked this with your screenshots provided and you can see that in the specific timeframes with crazy numbers there are input values equal to zero.
So what to do now:
You can either insert your snippet or my snippet in your final script - they should act the same as they set a default value for processVal of zero in case the input metrics are zero, too and don't try to do any math on the zero numbers.
If I understood correctly, you already have a "fixed" version in your lower environment where I expect everything to run fine, right? So you should adopt this change to production. Please remind I can just try to help on a community base, this is not an official CA recommendation and there is no responsibility in case it doesn't work. Nevertheless in case it doesn't solve the situation, you can easily revert to the state before by getting back to the old, current, OOTB javascript calculator.
So finally, your script should look like that:
// Sample Javascript code for Wily Introscope
//
// Compute the HOST CPU Load and percentage of Load that attributable to the process
//
function execute(metricData,javascriptResultSetHelper)
{
var i=0; // binding iterator
var agentList = {}; // list of agents we touch
var agentProcessCPU = {}; // how much cpu is used by the process by agent
var agentSystemLoad = {}; // how much cpu is used by the host (cumulative, all cpus)
var agentNumProcessors = {}; // number of cpus (needed for averaging)
var agentFrequency = {}; // array of frequency by agent
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;
// if we haven't seen this agent yet add it to the list of known agents
if (agentList[agent] == null)
{
agentList[agent] = agent;
}
// prep arrays for this agent, if necessary
if (agentSystemLoad[agent] == null)
{
agentSystemLoad[agent] = 0;
agentNumProcessors[agent] = 0;
agentProcessCPU[agent] = 0;
}
// stick the value in the right array -- if this is a CPU metric rather than the process metric,
// increase the CPU count for the host as well.
if (metric == "CPU:Utilization % (process)")
{
agentProcessCPU[agent] = value;
}
else
{
if (metric.indexOf("aggregate") > 0)
{
agentSystemLoad[agent] += value;
agentNumProcessors[agent] += 1;
}
}
agentFrequency[agent] = frequency;
}
// now iterate found agents and report calculated metrics
for (var agent in agentList) {
var averageCPUMetricName = agent + "|CPU:Host Average CPU (%)";
var processMetricName = agent + "|CPU:Process Load Proportion (%)";
var frequency = agentFrequency[agent];
// report a metric if we were aren't going to divide by zero
if (agentNumProcessors[agent] > 0)
{
var averageCPU = Math.round(agentSystemLoad[agent] / agentNumProcessors[agent]);
// add the calculated value to the result set
javascriptResultSetHelper.addMetric(averageCPUMetricName,
averageCPU,
javascriptResultSetHelper.kIntegerPercentage,
javascriptResultSetHelper.kDefaultFrequency)
var processVal = 0;
if (averageCPU > 0) {
processVal = Math.round((agentProcessCPU[agent]/averageCPU)*100);
}
javascriptResultSetHelper.addMetric(processMetricName,
processVal,
// the result type
javascriptResultSetHelper.kIntegerPercentage,
javascriptResultSetHelper.kDefaultFrequency)
}
}
// return the result set
return javascriptResultSetHelper;
}
// Tell the EM what Agents we should match against
function getAgentRegex()
{
return ".*";
}
// The the EM what metrics we should match against
function getMetricRegex()
{
return "CPU.*";
}
// 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 false;
}
Cheers
Stefan