Thursday, July 24, 2014

GSoC Week 10: Application Indicators - Getting user log in count chart


Since my previous attemp of getting logging in users through a SessionListener failed, this week i started back with two alternatives.

1. As suggested by my mentor Pascal, i tried to use a scheduler task for this. But since the task also doesn't have HTTPSession infomation this was not successful.

2. Created a new UI button to enable user login data tracking. When it is tirggerred the HTTPSession of the servlet request is passed to the Collector thread and logged in user count is retirved and stored into the databse from here onwards.

Below is how it is done.

I added a button to UI to click to enable login indicator. When user clicks this button it starts the LoggedInUsersCountCollectorThread with the session as below.


@RequestMapping(value = "/module/systemmetrics/track", method = RequestMethod.GET)
public void track(HttpServletRequest request)
{
loggedInUsersCountCollectorThread = new LoggedInUsersCountCollectorThread(request.getSession());
Thread loginThread = new Thread(loggedInUsersCountCollectorThread);
loginThread.start();
}


After that i can use the current session and get logged in users from time to time. This is similar to how the OpenMRS Core --> Administration --> Maintenance --> View logged in users section is also getting the users list.

Below is the chart view of the stored data which is calculated every 30 seconds.



Here are the commits i made for the feature within this week. 
  • https://github.com/openmrs/openmrs-module-systemmetrics/commit/e9a36740f2eddf35e6d5e435c13286735aecf0be
Since there is a new JIRA project is created for our project now i created the first feature entry there.
  • https://issues.openmrs.org/browse/SPU-1

Sunday, July 20, 2014

GSoC Week 09 - Starting with Application Indicators

This week i started with application indicators and as discussed previously with Pascal and Jan my first indicator to work on is Logged-in users count. Therefore i tried to record data on Logged In users.


However currently i have blocked a bit in that in by this week.


I first created the relevant table structure, DAO objects etc. for LoginValue DAO where we can store [timestamp, metric_id, logged in user count] records. Then in order to retrieve data on user log-ins i created a collector thread and implemented it with HTTPSessionListener class. So when the system starts the login data collector thread would run in each 30 seconds and create LoginValue entry and add it into data table. Then we can retrieve data from this table and draw the graph.


My intention was that when a user logs in, the sessionCreated() event will be triggered in this LoggedInUsersCountCollectorThread collector class which is given below.


public class LoggedInUsersCountCollectorThread implements Runnable, HttpSessionListener {


private boolean start;
LoginValue loginValue;
List<String> currentUsers = new ArrayList<String>();


PerformanceMonitoringService performanceMonitoringService;

public LoggedInUsersCountCollectorThread() {
           startLoggedInUsersCountCollectorThread();
}

@Override
public void run() {
Context.openSession();
performanceMonitoringService = Context.getService(PerformanceMonitoringService.class);
while (start){
int userCount = currentUsers.size();
loginValue = new LoginValue(System.currentTimeMillis(),3,userCount);
performanceMonitoringService.addLoginValue(loginValue);
try {
System.out.println("Users count " + userCount + " - sleeping 30s now");
Thread.sleep(30000);
} catch (InterruptedException e) 
{ /* ignore*/  }
    }
}

private boolean isStarted(){
return start;
}

public void startLoggedInUsersCountCollectorThread(){
start = true;
}

public void stopLoggedInUsersCountCollectorThread(){
start = false;
}

@Override
public void sessionCreated(HttpSessionEvent httpSessionEvent) {
currentUsers = CurrentUsers.getCurrentUsernames(httpSessionEvent.getSession());
System.out.println("User logged in " + currentUsers.size());
}


@Override
public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
System.out.println("User logged out " + currentUsers.size());
}



However this listener doesn't trigger when i started the module. My other functions works as expected and it updates the table etc. however since this thread always returns currentUsers list size as zero ( as sessionCreated event never triggered), the count is always recorded as 0 so i am unable to proceed to draw tables. I also tried with adding a listener entry into override-web.xml file in OpenMRS/test/resource directory as this but no luck.


<listener>
<listener-class>org.openmrs.module.systemmetrics.api.collectors.LoggedInUsersCountCollectorThread</listener-class>
</listener>



I will be discussing this with Pascal on the weekly update call this Monday and will get his advice. Based on that i hope i can correct if there is any issue or else i will be moving to try an alternative way.

Sunday, July 13, 2014

GSoC Week 08: System Performance and Utilization Module v1.0.0 Released !!

This week i released the first public available version of System Performance and Utilization Module. The  'systemmetrics-1.0.omod' is now available in the OpenMRS module repository and i created the corresponding Git tags v1.0.0 as well as the module documentation.

Below i would like to mention the useful references that helped me in releasing a module against github.


1. Releasing a module

https://wiki.openmrs.org/display/docs/Module+Tagging+and+Releasing

Once you follow the given instructions github will be automatically having the release tag in the git hub repo as below.

https://github.com/openmrs/openmrs-module-systemmetrics/releases

However i still need to deploy the module artifacts into remote nexus repository as i currently don't have access for it. I have submitted an access request and awaiting response on it.

2. Module Repository Location

https://modules.openmrs.org/#/show/162/system-performance-and-utilization-module

3. Module Documentation

https://wiki.openmrs.org/display/docs/System+Performance+and+Utilization+Module

4. Module Source Repository


There are few tasks for me to getting done with the 1.0.0 version. First one is deploying the artifacts into nexus. then create a JIRA project and also upload a video on using the module. While working on these things getting done, i hope to move into Application Indicators Implementation from next week too.

Sunday, July 6, 2014

GSoC Week 07 - Ready for the first release !!

This week i mostly worked on getting used memory indicator finalized for the very first 1.0.0 release of OpenMRS-SystemMetrics module. The final agreement for the release between me and my mentors was get the Memory indicator finalized with Service API and the Graph and releasing it out by the next week.

I was able to work on towards this and complete the memory data during this week and covered the tasks below.

1. Modified the per second memory value graph.

2. Added the next graph on per minute memory values for the Used Memory.

3. Added schedulers to delete the data from per second and per minute data tables in the database periodically. The current time duration is per second data will be deleted in every 30 minutes and per minute data will be cleared in every 5 hours to avoid these tables getting flooded. Evetually these values will be make configurable using global properties so users have the freedom of configuring those as they need.

4. Modified the Module home page and provided links to view the charts and tables.

Module Home Page:



Used Memory Charts page:




For the next week i hope to finish the documentation so far, create the JIRA project and create the first video of the System Performance and Utilization Module and release 1.0.0 version of the module.

Once we get the release out the next task would be start on Application indicators and get the data on logged in users statistics and display it in the module.