Building a tool to monitor who is logged on to an SAP NetWeaver Portal…
One of the most commonly asked questions in the portal forums is how to see who is logged on to a portal. While I’m not completely sure why people want to know this, I decided to try and put together a tool to help. “);
out.close();
File uFile = new File(“
temp
user_”+from);
BufferedWriter o1 = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(uFile,false), “UTF8”));
o1.write(L.toString());
o1.close();
} catch (Exception e) {};
}
public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)
{
}
}
A bit of testing of the component by POSTing from a static HTML form seems to do the trick, so it’s now time to replace the runtime version of the current SessionManager.jsp. This is done as a portal admin by restarting the com.sap.netweaver.coll.appl.ui.rtc archive: System admin -> Support -> Portal Runtime -> Application Console Find com.sap.netweaver.coll.appl.ui.rtc And then restart.
Now we need a quick portal component to report on files in \temp with a last stored date within the last 10 seconds and I have a component for listing currently logged on users:
package com.sap.anz;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.Date;
import com.sapportals.portal.prt.component.AbstractPortalComponent;
import com.sapportals.portal.prt.component.IPortalComponentRequest;
import com.sapportals.portal.prt.component.IPortalComponentResponse;
public class List extends AbstractPortalComponent
{
public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)
{
response.write(“h2. Currently logged on users
“);
Date now = new Date();
long l = now.getTime();
try {
File dir = new File(“
temp”);
File[] fs = dir.listFiles();
for( int i = 0, ii = fs.length; i < ii; i++ ) {
String thisone = fs[i].getName();
if (thisone.startsWith(“user_”)) {
File f = new File(“
temp
“+thisone);
BufferedReader i1 = new BufferedReader(new FileReader(f));
String line = i1.readLine();
i1.close();
long diff = l – new Long(line).longValue();
if (diff < 10000) // seconds * 1000
response.write(“
“+thisone.substring(5));
}
}
} catch (Exception e) {
}
}
}
There are a few hassles however... First, do you count people who start portal components directly? These users don't have the ping running. Same with non-portal Java apps - how do we ping their sessions.
great blog - I learned a lot about the portal. I guess another approach would be to select the users who have a currently active session, i.e. whose session has not timed out. The downside would be that it would display users who closed their browsers 10 minutes ago (how long is the time-out?), the up-side would be that you see those who bypass the portal (no /irj) and maybe just run a Web Dynpro or JSP application on the server. What do you think?
Cheers,
Thorsten
Yeah, tracing this stuff down teaches you a lot about the portal! The main issue with looking at sessions is that they are tied to instances and server nodes, so you'd need some way to collect this info cross server. Also, if someone launches, for example, an iView that starts webgui, then the session would expore, but they're still effecively using the portal..
With all options there are pluses and minuses!