DX Application Performance Management

  • 1.  JavaScript addMetric Error

    Posted Oct 21, 2013 06:00 PM
    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?


  • 2.  RE: JavaScript addMetric Error

    Broadcom Employee
    Posted Oct 21, 2013 06:57 PM
    Just to level-set everyone, what version of APM are you using?


  • 3.  RE: JavaScript addMetric Error

    Posted Oct 22, 2013 10:25 AM

    hdavis wrote:

    Just to level-set everyone, what version of APM are you using?
    9.1.5.0


  • 4.  RE: JavaScript addMetric Error

    Posted Oct 22, 2013 11:05 AM
    Try take away the[b] ( ) in the regular expression.

    // 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";
    }


  • 5.  RE: JavaScript addMetric Error

    Posted Oct 22, 2013 01:26 PM

    VLu wrote:

    Try take away the[b] ( ) in the regular expression.

    // 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";
    }
    That doesn't matter. Still get the error. Those two functions work fine, it is calling the addMetric function that fails.
    By the way, I have a 9.5.0 environment that I tried it on and it failed there as well.


  • 6.  RE: JavaScript addMetric Error

    Posted Oct 22, 2013 05:38 PM
    Hi,

    It seems to me that there some problem with the method definition.
    I am not sure, but can you try the below options -

    1. Remove "java.lang.Integer(svrSTCount)" parameter from the addmetric method. Explicit type casting may be creating some problem.

    Current:
    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);

    Required:
    javascriptResultSetHelper.addMetric(metricName, javascriptResultSetHelper.kIntegerPercentage, frequency);

    2. Provide spaces between the parameters ( I am not hopeful with this, but just try it out )

    Current:
    javascriptResultSetHelper.addMetric(metricName,java.lang.Integer(svrSTCount),javascriptResultSetHelper.kIntegerPercentage,frequency);

    Required:
    javascriptResultSetHelper.addMetric(metricName, java.lang.Integer(svrSTCount), javascriptResultSetHelper.kIntegerPercentage, frequency);



    Regards,
    Vaibhav


  • 7.  RE: JavaScript addMetric Error

    Posted Oct 23, 2013 10:51 AM

    viruvaibhav_apm wrote:

    Hi,
    ...
    1. Remove "java.lang.Integer(svrSTCount)" parameter from the addmetric method. Explicit type casting may be creating some problem.
    ...
    Required:
    javascriptResultSetHelper.addMetric(metricName, javascriptResultSetHelper.kIntegerPercentage, frequency);
    ...
    2. Provide spaces between the parameters ( I am not hopeful with this, but just try it out )
    ...
    Required:
    javascriptResultSetHelper.addMetric(metricName, java.lang.Integer(svrSTCount), javascriptResultSetHelper.kIntegerPercentage, frequency);
    ...
    For #1, if the count is removed then there would not be a point to write the metric. It would just have a metric name but not a value.
    For #2, I took that long shot as well and it didn't help.


  • 8.  RE: JavaScript addMetric Error
    Best Answer

    Posted Oct 23, 2013 11:23 AM
    Hi

    I've seen this error before, if you examine line 45 of the script you have:-

    javascriptResultSetHelper.addMetric(metricName,java.lang.Integer(svrSTCount),javascriptResultSetHelper.kIntegerPercentage,frequency);

    the problem is caused by defining frequency as a number before hand:-

    var frequency = 15;

    To overcome problem you need to define frequency as:-

    var frequency = Packages.com.wily.introscope.spec.metric.Frequency.getFrequencyInSeconds(15);

    Knowledge document TEC598179 covers this problem in more detail.

    Hope this helps
    Christopher Clark
    CA Support


  • 9.  RE: JavaScript addMetric Error

    Posted Oct 23, 2013 12:04 PM
    Thanks Chris! That fixed the problem.