AnsweredAssumed Answered

javascript calculator per agent

Question asked by SKumarN on Aug 14, 2014
Latest reply on Aug 18, 2014 by jakbutler

sHi, I have a javascript calculator that subtracts some timeouts and signoffs from the total users signed in.  We want to determine how many active users are online at any given point.  I am attaching the javascript as below.  Currently this solution is working fine.  But, the issue that we have is, this gives us only a total across all agents.  We need to determine the active users per agent.  How do we modify the javascript for that?  Or is it possible at all?

 

Thanks for your help

 

Skumar

 

// MobileSessions.js
//
// Compute the difference in session count between authenticated and signon fiinished for EPAgent Mobile
//
function execute(metricData,javascriptResultSetHelper)
{

    // for each input agent, compute a calculated metric named
    // "<metric>|<agentname>:Average Response Time (ms)" as
    // that agent's "Math.round(Total Response Time / Count)".


    var i=0;     // binding iterator
    var agentList = {};   // list of agents
    var agentSession = {};   // array of Total values by agent
    var agentSignoff = {};   // array of Signoff values by agent
    var agentTimedout = {};   // array of Timedout values by agent
    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;

        // add to agentList if we haven't seen the agent yet
        if (agentList[agent] == null)
        {
            agentList[agent] = agent;
        }

  // put the value in the right array
        if (metric == "Mobile Sessions:Sign on")
        {
            agentSession[agent] =  value;
        }
       
        if (metric == "Mobile Sessions:Sign off")
        {
            agentSignoff[agent] =  value;
        }

        if (metric == "Mobile Sessions:Time out")
        {
            agentTimedout[agent] =  value;
        }

        agentFrequency[agent] =  frequency;
    }


    // now iterate found agents and report calculated metrics, build array of metrics
    for (var agent in agentList)
    {
// set up metric name
var metricName = agent + "|Mobile Sessions:Concurrent Sessions";
        var frequency = agentFrequency[agent];

var diffValue = 0;
        if (agentSession[agent] > 0 && agentSignoff[agent] >= 0 && agentTimedout[agent] >= 0)
        {
  // perform the math
  diffValue = agentSession[agent] - agentSignoff[agent] - agentTimedout[agent];
        }

        if (diffValue < 0)
  diffValue = 0;
     
var count=diffValue;

// add the calculated value to the result set
     javascriptResultSetHelper.addMetric(metricName,
                        count,
                        0,
                        diffValue,
                        diffValue,
                        javascriptResultSetHelper.kLongIntervalCounter,
                        frequency);
    }

    // return the result set
    return javascriptResultSetHelper;

}

// Tell the EM what agents we should match against
function getAgentRegex()
{
    return ".*";
}

// Tell the EM what agent metrics we should match against
function getMetricRegex()
{
    return "Mobile Sessions:(Sign off|Sign on|Time out)";
}

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

Outcomes