cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Axeda: How to monitor concurrent user logins on the Axeda Platform

Level 5

Axeda: How to monitor concurrent user logins on the Axeda Platform

This article explains how to monitor concurrent user logins on the Axeda Platform. Its going to do this by creating an asset to monitor the solution. This asset will have a dataitem that tracks the users logged in. You can use this dataitem to trend usage during the day, or calculate the max per day. Or you could alarm if the number of users goes over some limit.

The following needs to be created on your Platform :
A model named “Monitor”, containing an analog DataItem named “userlogins” and an asset named “Metrics” This asset will receive the values.

Expression Rule:


Create two expression rules that update the number of users, triggered on user login or logout:

Name : UserLoginMonitor

Type: Userlogin and Userlogout (two rules required)

IF:     true

THEN: ExecuteCustomObject(“getUserLogins”, User.total)

This calls a script and passes in User.total  = The total number of users that are logged into the system (Concurrently).

Groovy Script (Custom Object)


Now, the next step is to write a Groovy Script (Custom Object)
You can copy and paste the following code into your Groovy script.

Give the script a name : getUserLogins


This script also has a parameter named logins


import com.axeda.drm.sdk.device.DataItem;

import com.axeda.drm.sdk.device.Device;

import com.axeda.drm.sdk.Context

import com.axeda.drm.sdk.device.DataItemFinder;

import com.axeda.drm.sdk.device.ModelFinder;

import com.axeda.drm.sdk.device.DeviceFinder;

import com.axeda.drm.sdk.data.DataValueEntry

import com.axeda.drm.sdk.device.Model;

import com.axeda.drm.sdk.data.CurrentDataFinder;

import com.axeda.drm.sdk.data.DataValue;

def logins= parameters.logins

def ctx = Context.create()

def mod = loadModel("Monitor",ctx)

def dev = loadDevice("Metrics",mod,ctx)

DataItemFinder dif = new DataItemFinder(ctx)

dif.setModel(mod)

dif.setDataItemName("userlogins")

DataItem di = dif.find()

DataValueEntry dve = new DataValueEntry(ctx, dev, di, logins)

dve.store()

    public void setDataItem(String dataItemName, Integer dataItemValue, Device device, Context context)

    {

        DataItemFinder dif = new DataItemFinder(ctx);

        dif.setDataItemName(dataItemName);

        dif.setModel(device.getModel());

        DataItem di = dif.find();

        DataValueEntry dve = new DataValueEntry(ctx, dev, di, newValue)

        dve.store()

    }

    public DataValue findCurrentDataItemValue(Device device, String dataItemName,Context ctx)

    {

        CurrentDataFinder cdFinder =  new CurrentDataFinder(ctx,device);

        DataValue dv = cdFinder.find(dataItemName);

        return dv;

    }

    public DataItem loadDataItem(Model model,String dataItemName, Context ctx)

     {

        DataItemFinder iFinder = new DataItemFinder(ctx);

        iFinder.setDataItemName(dataItemName);

        iFinder.setModel(model);

        return iFinder.find();

    }

    public Model loadModel(String modelNumber, Context ctx)

    {

        ModelFinder mf = new ModelFinder(ctx);

        mf.setName("Monitor");

        return mf.find();

    }

    public Device loadDevice(String serialNumber,Model model, Context context ) {

        DeviceFinder df = new DeviceFinder(context);

        df.setSerialNumber(serialNumber);

        df.setModel(model);

        return df.find();

    }

Whenever a user logs into the Axeda Platform, the Metrics asset will show the concurrent number of logged in users in the Platform. This dataitem can be graphed to see the pattern of usage.

If you wanted to take action based on the number of users, create an expression rule to alarm when a threshold is reached. This rule should be associated with the model "Monitor".

Name : LoginsCheck

Type: Data

IF:     userlogins > 40

THEN: CreateAlarm("Login limit", 100, str(userlogins)+" users")

Now an alarm is created each time too many users are logged in. An alarm can be used for notifications or viewed on the Monitor asset.

Tags (1)