DX Application Performance Management

  • 1.  Subtraction Calculator

    Posted Oct 31, 2016 10:26 AM

    Hi,

     

    I need to create a subtraction calculator, I have 2 metrics and need to subtract them and create a new metric, someone here have a subtract script model? I create this, but doesn't works

     

     

     function execute(metricData,javascriptResultSetHelper) {
        var currentDate = new Date();
     } 
     
     // number of 15-second intervals to be averaged out
     var numberOfIntervals = 5;

     // which metric name you want reported as reliability
     var ThreadsActiveCountMetricName = "ThreadActiveCount";

     // you should set this to the metric path that you want to consider by this calculator
     // each capturing group defined in the regexp below (ie, each group captured by '()') must be defined in
     // the function formatMetric below
     var metricTreeRegExp = "*SuperDomain*\\|(.*)\\|WAS7_WPS6A\\|WebSphere\\|Threads\\|(.*)";
     
     // function that is called to define each group where reliability will be calculated
     // it must respect the number of capturing groups defined in variable metricTreeRegExp
     // for example:
     //                metricTreeRegExp = "Business Service\\|(.*)\\|Business Transactions\\|(.*) \\- (.*)"
     //                groupParameters[1] = first (.*) above
     //                groupParameters[2] = second (.*) above
     //                groupParameters[1] = third (.*) above
     //                and so on...
     var formatMetric = function(groupParameters) {
        return "*SuperDomain*|" + groupParameters[1] + "|WAS7_WPS6A|" + "|WebSphere|Threads|" + groupParameters[2];
    };

        // Para cada agente inputado, cria uma nova métrica calculada
        // "JavaScript|<agentname>:ThreadActiveCount" as
        // that agent's "Thread Create" - "Thread Destroy".
        var i=0;
        var agent2ThreadActiveCount = {};
        for(i=0; i < metricData.length; i++) {
            var metric = metricData[i].ESEAttribute.attributeURL;
            var agent = metricData[i].ESEProcess.processURL;
            var value = metricData[i].timeslicedValue.value;
            // set to 0 if we haven't seen this agent yet
            if (agent2ThreadActiveCount[agent] == null) {
                agent2ThreadActiveCount[agent] = 0;
            }
            // somewhat hacky way to subtract, but I can't determine
            // the order in which I'll see data.
            if (metric == "ThreadPool:Thread Create") {
                agent2ThreadActiveCount[agent] +=  value;
            } else {
                agent2ThreadActiveCount[agent] -=  value;
            }
        }
        // now iterate found agents and report calculated metrics
        for (var agent in agent2ThreadActiveCount) {
            var metricName = "JavaScript|"+agent+":ThreadsActiveCount";
            var value = agent2ThreadActiveCount[agent];
            accumulatorFactory.getLongFluctuatingCounterDataAccumulator(
                metricName).ILongCounterDataAccumulator_setValue(value);       
        }
     // cria a nova metrica de ActiveCount
        var ThreadsActiveCountMetric = metricData[0].agentName.processURL + "|" + groupName + ":" + ThreadsActiveCountName;
     
        javascriptResultSetHelper.addMetric(ThreadsActiveCountMetric,
      ThreadsActiveCount,
      Packages.com.wily.introscope.spec.metric.MetricTypes.kIntegerFluctuatingCounter,
      metricData[0].frequency);
      
    function getAgentRegex() {
        return ".*\|WebSphere\|WAS7_WPS6A";
    }
    function getMetricRegex() {
        return "ThreadPool.*";



  • 2.  Re: Subtraction Calculator

    Broadcom Employee
    Posted Oct 31, 2016 11:27 AM

    You can start to debug your problem by logging your variables to the EM log file: https://communities.ca.com/docs/DOC-231151741

     



  • 3.  Re: Subtraction Calculator

    Broadcom Employee
    Posted Oct 31, 2016 11:40 AM

    Converting to a discussion since it involves custom code.



  • 4.  Re: Subtraction Calculator

    Broadcom Employee
    Posted Nov 02, 2016 09:47 AM

    Ok to start with, you say it doesn't work, but there is no more additional info on what is not working.  However at first glance, your execute function ends before encapsulating the rest of the code.

     

    You have this below.  All execute will do is get the new date and that's it.  You need to fix this.

     

    function execute(metricData,javascriptResultSetHelper) {
        var currentDate = new Date();
     }