Skip to content

Latest commit

 

History

History
89 lines (72 loc) · 2.73 KB

2015-07-15-number-of-online-users-alfresco.md

File metadata and controls

89 lines (72 loc) · 2.73 KB
layout title date comments categories description tags
post
Get list of currently logged users
2015-07-15 13:23:45 -0700
true
For monitoring of Alfresco we needed to somehow get a number of users currently logged in Alfresco. Here I'm showing how to easily get number of such users as well as list of usernames using simple webscript.
alfresco

Introduction

For monitoring of Alfresco we needed to somehow get a number of users currently logged in Alfresco. Here I'm showing how to easily get number of such users as well as list of usernames using simple webscript. This post is based on an answer by mrgrechkin on Alfresco forum.

Webscript

Write a description file:

{% highlight xml %} Statistics Return json with stats for application Stats draft_public_api /mycomp/api/getStatistics admin {% endhighlight xml %}

Webscript implementation:

{% highlight java %} public class GetStatistics extends AbstractWebScript { @Autowired private TicketComponent ticketComponent;

@Override public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException { JSONObject users = new JSONObject(); JSONObject response = new JSONObject();

users.put("online", getNumberOfUsersConnected());
response.put("users", users);

res.getWriter().write(response.toJSONString());

}

/**

  • Return approximate number of users, whose ticket didn't expired yet.
  • By default alfresco ticket expires after one hour of user's inactivity
  • @return number of users who were connected less that one hour ago */ private int getNumberOfUsersConnected() { Set connectedUsers = ticketComponent.getUsersWithTickets(true); return connectedUsers.size(); } } {% endhighlight java %}

And register webscript in your-app-context.xml:

{% highlight xml %} {% endhighlight xml %}

At the end after calling webscript's URL: /alfresco/s/mycomp/api/getStatistics you'll get this output:

{% highlight json %} { "users": { "online": 4 }, "usernames": "["dduck","mmouse","pluto","System"]" } {% endhighlight json %}

And in this post: [REST call monitoring extension for AppDynamics]({{ site.url }}/2015/07/rest-monitor/) you will now how to use this webscript as a metric provider for AppDynamics.

Cheers!