I have followed the documentation and looked at existing JavaScript calculators to create a new one. I am getting an error though when I put the script in the scripts directory.
Here is the error
10/21/13 03:37:55.254 PM CDT [ERROR] [Harvest Engine Pooled Worker] [Manager.JavascriptEngine] Exception with script /Introscope_9150/./scripts/ProdStuckThreads-2.js: org.mozilla.javascript.EvaluatorException: Can't find method com.wily.introscope.server.beans.javascriptcalculator.CalculatorScript$JavascriptResultSetHelper.addMetric(string,java.lang.Integer,number,number). (/Introscope_9150/./scripts/ProdStuckThreads-2.js#45)
org.mozilla.javascript.EvaluatorException: Can't find method com.wily.introscope.server.beans.javascriptcalculator.CalculatorScript$JavascriptResultSetHelper.addMetric(string,java.lang.Integer,number,number). (/Introscope_9150/./scripts/ProdStuckThreads-2.js#45)
at org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:95)
at org.mozilla.javascript.Context.reportRuntimeError(Context.java:966)
at org.mozilla.javascript.Context.reportRuntimeError(Context.java:1022)
at org.mozilla.javascript.Context.reportRuntimeError1(Context.java:985)
at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:158)
at org.mozilla.javascript.optimizer.OptRuntime.callN(OptRuntime.java:84)
at org.mozilla.javascript.gen.c42._c1(/Introscope_9150/./scripts/ProdStuckThreads-2.js:45)
at org.mozilla.javascript.gen.c42.call(/Introscope_9150/./scripts/ProdStuckThreads-2.js)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:337)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2755)
at org.mozilla.javascript.gen.c42.call(/Introscope_9150/./scripts/ProdStuckThreads-2.js)
at com.wily.introscope.server.beans.javascriptcalculator.CalculatorScript.evaluate(CalculatorScript.java:304)
at com.wily.introscope.server.beans.javascriptcalculator.CalculatorScript.safeEvaluate(CalculatorScript.java:269)
at com.wily.introscope.server.beans.javascriptcalculator.JavascriptCalculatorBean$CalculatorWrapper.handleData(JavascriptCalculatorBean.java:502)
at com.wily.introscope.server.beans.metriccalculator.MetricCalculatorBean$RegisteredCalculator.handleData(MetricCalculatorBean.java:1118)
at com.wily.introscope.spec.server.beans.metricdata.AMetricDataNotification.handleData(AMetricDataNotification.java:33)
at com.wily.introscope.server.beans.metricdata.live.AsyncQueryTracker.stopHarvest(AsyncQueryTracker.java:360)
at com.wily.introscope.server.beans.metriccalculator.MetricCalculatorBean$RegisteredCalculator.run(MetricCalculatorBean.java:817)
at com.wily.EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:728)
at java.lang.Thread.run(Thread.java:662)
Here is my script--
// Sample Javascript code for Wily Introscope
//
// Check for the number of Prod3 servers that have stuck threads
// Look for how many servers have >0 stuckThreads
//
function execute(metricData,javascriptResultSetHelper)
{
var i=0; // binding iterator
var agentList = {}; // list of agents
var agentFrequency = {}; // array of frequency by agent
var svrCount=0;
var svrSTCount=0;
for(i=0; i < metricData.length; i++)
{
var metric = metricData.agentMetric.attributeURL;
var agent = metricData[i].agentName.processURL;
var value = metricData[i].timeslicedValue.value;
//svrCount will be used to see if all the servers are reporting in.
svrCount++;
// There is no reason why this shouldn't be StuckThreadCount.
// Checking anyway.
if (metric == "(.*)WorkManagerRuntime:StuckThreadCount")
{
//if the value is more than 0 then increment the svrSTCount.
if( value>0) {
svrSTCount++;
}
}
}
// Just to a spot check if six servers were found.
if (svrCount != 6){
log.info("The Prod Stuck Thread JS calcualtor found a different number of servers than were expected. 6 were expected, "+svrCount+" were found.");
}
//
//Send the results
//
var metricName="SuperDomain|Custom Metric Host (Virtual)|Custom Metric Process (Virtual)|Custom Metric Agent (Virtual)|Prod Prod|Prod3 StuckThreads:Servers With StuckThreads";
var frequency = 15;
javascriptResultSetHelper.addMetric(metricName,java.lang.Integer(svrSTCount),javascriptResultSetHelper.kIntegerPercentage,frequency);
//javascriptResultSetHelper.addMetric(metricName, svrSTCount, svrSTCount,svrSTCount,Packages.com.wily.introscope.spec.metric.MetricTypes.kIntegerFluctuatingCounter, frequency);
var metricName="SuperDomain|Custom Metric Host (Virtual)|Custom Metric Process (Virtual)|Custom Metric Agent (Virtual)|Prod|Prod3 StuckThreads:Total Servers";
javascriptResultSetHelper.addMetric(metricName,java.lang.Integer(svrCount),javascriptResultSetHelper.kIntegerPercentage,frequency);
//javascriptResultSetHelper.addMetric(metricName, 1, svrCount, svrCount, svrCount, Packages.com.wily.introscope.spec.metric.MetricTypes.kIntegerFluctuatingCounter, frequency);
// return the result set
return javascriptResultSetHelper;
}
// Tell the EM what agents we should match against
function getAgentRegex()
{
return "(.*)server2[1-3]\\|WebLogic\\|prod\\.node(.*)";
}
// Tell the EM what agent metrics we should match against
function getMetricRegex()
{
return "JMX\\|com\\.bea\\|ApplicationRuntime=prod(.*)Name=default\\|ServerRuntime=(.*)\\|(.*)WorkManagerRuntime:StuckThreadCount";
}
// 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;
}
I have also tried using the addMetric with addMetric(metricName, count, value, min, max, metricType, frequency), and different types in metric but always got the same type of error.
IntroscopeEnterpriseManager.log:org.mozilla.javascript.EvaluatorException: Can't find method com.wily.introscope.server.beans.javascriptcalculator.CalculatorScript$JavascriptResultSetHelper.addMetric(string,number,number,number).
IntroscopeEnterpriseManager.log:org.mozilla.javascript.EvaluatorException: Can't find method com.wily.introscope.server.beans.javascriptcalculator.CalculatorScript$JavascriptResultSetHelper.addMetric(string,number,number,number,number,number).
IntroscopeEnterpriseManager.log:org.mozilla.javascript.EvaluatorException: Can't find method com.wily.introscope.server.beans.javascriptcalculator.CalculatorScript$JavascriptResultSetHelper.addMetric(string,java.lang.Integer,number,number).
IntroscopeEnterpriseManager.log:org.mozilla.javascript.EvaluatorException: Can't find method com.wily.introscope.server.beans.javascriptcalculator.CalculatorScript$JavascriptResultSetHelper.addMetric(string,java.lang.Integer,java.lang.Integer,java.lang.Integer).
IntroscopeEnterpriseManager.log:org.mozilla.javascript.EvaluatorException: Can't find method com.wily.introscope.server.beans.javascriptcalculator.CalculatorScript$JavascriptResultSetHelper.addMetric(string,java.lang.Integer,java.lang.Integer,java.lang.Integer,java.lang.Integer,java.lang.Integer,java.lang.Integer).
What paramaters are in a valid addMetric method?