felipe.scastro

Subtraction Calculator

Discussion created by felipe.scastro on Oct 31, 2016
Latest reply on Nov 2, 2016 by musma03

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.*";

Outcomes